Skip to content

Commit 24b7c72

Browse files
[autofix.ci] apply automated fixes
1 parent ad38c69 commit 24b7c72

File tree

3 files changed

+67
-73
lines changed

3 files changed

+67
-73
lines changed

src/sql/postgres/protocol/ErrorResponse.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ fn getConditionName(error_code: String) ?[]const u8 {
271271
if (error_code.eqlComptime("XX000")) return "internal_error";
272272
if (error_code.eqlComptime("XX001")) return "data_corrupted";
273273
if (error_code.eqlComptime("XX002")) return "index_corrupted";
274-
274+
275275
return null;
276276
}
277277

@@ -282,35 +282,35 @@ const KeyValuePair = struct {
282282

283283
fn parseKeyValueFromDetail(detail: String, allocator: std.mem.Allocator) ?KeyValuePair {
284284
if (detail.isEmpty()) return null;
285-
285+
286286
const detail_str = detail.toUTF8WithoutRef(allocator);
287287
defer detail_str.deinit();
288288
const detail_slice = detail_str.slice();
289-
289+
290290
// Parse format: "Key (column_name)=(value) already exists."
291291
if (std.mem.indexOf(u8, detail_slice, "Key (")) |start| {
292292
const after_key = start + 5; // "Key (".len
293293
if (std.mem.indexOf(u8, detail_slice[after_key..], ")=(")) |end_key_relative| {
294294
const end_key = after_key + end_key_relative;
295295
const key = detail_slice[after_key..end_key];
296-
296+
297297
const value_start = end_key + 3; // ")=(".len
298298
if (std.mem.indexOf(u8, detail_slice[value_start..], ") ")) |end_value_relative| {
299299
const end_value = value_start + end_value_relative;
300300
const value = detail_slice[value_start..end_value];
301-
301+
302302
// Allocate and copy the strings
303303
const key_copy = allocator.dupe(u8, key) catch return null;
304304
const value_copy = allocator.dupe(u8, value) catch {
305305
allocator.free(key_copy);
306306
return null;
307307
};
308-
308+
309309
return KeyValuePair{ .key = key_copy, .value = value_copy };
310310
}
311311
}
312312
}
313-
313+
314314
return null;
315315
}
316316

@@ -397,7 +397,7 @@ pub fn toJS(this: ErrorResponse, globalObject: *jsc.JSGlobalObject) JSValue {
397397
bun.default_allocator.free(kv.key);
398398
bun.default_allocator.free(kv.value);
399399
};
400-
400+
401401
if (code.eqlComptime("23505") and !detail.isEmpty()) {
402402
key_value_data = parseKeyValueFromDetail(detail, bun.default_allocator);
403403
}

test/js/sql/postgres-error-condition-mapping.test.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe("PostgreSQL Error Condition Mapping", () => {
66
// These tests verify that our mapping logic would work correctly
77
// We can't test the actual Zig functions directly from JS, but we can verify
88
// that the error codes we expect are correctly mapped
9-
9+
1010
const expectedMappings = [
1111
{ code: "23505", condition: "unique_violation" },
1212
{ code: "23502", condition: "not_null_violation" },
@@ -32,25 +32,25 @@ describe("PostgreSQL Error Condition Mapping", () => {
3232
// Test the pattern that would be used to parse detail messages
3333
const testCases = [
3434
{
35-
detail: 'Key (email)=([email protected]) already exists.',
36-
expectedKey: 'email',
37-
expectedValue: '[email protected]'
35+
detail: "Key (email)=([email protected]) already exists.",
36+
expectedKey: "email",
37+
expectedValue: "[email protected]",
3838
},
3939
{
40-
detail: 'Key (username)=(john_doe) already exists.',
41-
expectedKey: 'username',
42-
expectedValue: 'john_doe'
40+
detail: "Key (username)=(john_doe) already exists.",
41+
expectedKey: "username",
42+
expectedValue: "john_doe",
4343
},
4444
{
45-
detail: 'Key (id)=(12345) already exists.',
46-
expectedKey: 'id',
47-
expectedValue: '12345'
45+
detail: "Key (id)=(12345) already exists.",
46+
expectedKey: "id",
47+
expectedValue: "12345",
4848
},
4949
{
50-
detail: 'Key (complex_field)=(value with spaces) already exists.',
51-
expectedKey: 'complex_field',
52-
expectedValue: 'value with spaces'
53-
}
50+
detail: "Key (complex_field)=(value with spaces) already exists.",
51+
expectedKey: "complex_field",
52+
expectedValue: "value with spaces",
53+
},
5454
];
5555

5656
testCases.forEach(({ detail, expectedKey, expectedValue }) => {
@@ -69,22 +69,22 @@ describe("PostgreSQL Error Condition Mapping", () => {
6969
test("edge cases for key-value parsing", () => {
7070
const edgeCases = [
7171
{
72-
detail: 'Some other error message without key-value format',
73-
shouldMatch: false
72+
detail: "Some other error message without key-value format",
73+
shouldMatch: false,
7474
},
7575
{
76-
detail: 'Key (email)=([email protected]) already exists.',
77-
shouldMatch: true
76+
detail: "Key (email)=([email protected]) already exists.",
77+
shouldMatch: true,
7878
},
7979
{
80-
detail: '',
81-
shouldMatch: false
82-
}
80+
detail: "",
81+
shouldMatch: false,
82+
},
8383
];
8484

8585
edgeCases.forEach(({ detail, shouldMatch }) => {
8686
const keyMatch = detail.match(/Key \(([^)]+)\)=\(([^)]+)\)/);
8787
expect(!!keyMatch).toBe(shouldMatch);
8888
});
8989
});
90-
});
90+
});

0 commit comments

Comments
 (0)