MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / FormatParseErrorJSON

Function FormatParseErrorJSON

cmd/gosqlx/internal/output/json.go:377–401  ·  view source on GitHub ↗

FormatParseErrorJSON creates a JSON error output for parse failures

(err error, inputSource string)

Source from the content-addressed store, hash-verified

375
376// FormatParseErrorJSON creates a JSON error output for parse failures
377func FormatParseErrorJSON(err error, inputSource string) ([]byte, error) {
378 errCode := extractErrorCode(err)
379 output := &JSONParseOutput{
380 Command: "parse",
381 Input: JSONInputInfo{
382 Type: "query",
383 Files: []string{inputSource},
384 Count: 1,
385 },
386 Status: "error",
387 Error: &JSONParseError{
388 Message: err.Error(),
389 Code: errCode,
390 Type: categorizeByCode(errCode, err.Error()),
391 },
392 }
393
394 // Marshal to JSON with indentation
395 data, err2 := json.MarshalIndent(output, "", " ")
396 if err2 != nil {
397 return nil, fmt.Errorf("failed to marshal parse error JSON: %w", err2)
398 }
399
400 return data, nil
401}
402
403// determineInputType determines the type of input based on the file list
404func determineInputType(files []string) string {

Callers 1

TestFormatParseErrorJSONFunction · 0.85

Calls 4

categorizeByCodeFunction · 0.85
extractErrorCodeFunction · 0.70
ErrorfMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestFormatParseErrorJSONFunction · 0.68