Skip to content

[-] fix JSON serialization of different error types in task execution logging#744

Open
MaxaiZer wants to merge 2 commits intocybertec-postgresql:masterfrom
MaxaiZer:fix-error-logging
Open

[-] fix JSON serialization of different error types in task execution logging#744
MaxaiZer wants to merge 2 commits intocybertec-postgresql:masterfrom
MaxaiZer:fix-error-logging

Conversation

@MaxaiZer
Copy link
Contributor

Task errors are currently serialized inconsistently. If ExecuteSQLCommand fails during this block:

if len(paramValues) == 0 { 
  ct, e := executor.Exec(ctx, task.Command)
  pge.LogTaskExecution(context.Background(), task, errCodes[e != nil], ct.String(), "") 
  return e
}

message_data.error in the "Task execution failed" log will contain a full pgconn.PgError struct:

{"task": 1, "vxid": 1, "chain": 1, "error": {"Code": "42P02", "File": "parse_expr.c", "Hint": "", "Line": 901, "Where": "", "Detail": "", "Message": "there is no parameter $1", "Routine": "transformParamRef", "Position": 175, "Severity": "ERROR", "TableName": "", "ColumnName": "", "SchemaName": "", "DataTypeName": "", "InternalQuery": "", "ConstraintName": "", "InternalPosition": 0, "SeverityUnlocalized": "ERROR"}}

If it fails during parameter parsing:

if err = json.Unmarshal([]byte(val), &params); err != nil {
    return
}

message_data.error will contain struct with no actual error message:

{"task": 1, "vxid": 1, "chain": 1, "error": {"Type": {}, "Field": "", "Value": "string", "Offset": 9, "Struct": ""}}

And if ExecuteSQLCommand returns joined errors, message_data.error becomes empty:

{"task": 1, "vxid": 1, "chain": 1, "error": {}}

After fix examples:

  • single postgres error:
{"task": 1, "vxid": 1, "chain": 1, "error": "ERROR: there is no parameter $1 (SQLSTATE 42P02)"}
  • parameter parse error:
{"task": 1, "vxid": 1, "chain": 1, "error": "failed to parse parameter \"1 month\": json: cannot unmarshal string into Go value of type []interface {}"}
  • joined errors (task with two parameters: correct and incorrect):
{"task": 1, "vxid": 1, "chain": 1, "error": "ERROR: procedure F_CreatePartitions(date, date) does not exist (SQLSTATE 42883)\nfailed to parse parameter \"1 month\": json: cannot unmarshal string into Go value of type []interface {}"}

@pashagolub pashagolub self-assigned this Feb 13, 2026
@pashagolub pashagolub added the bug Something isn't working label Feb 13, 2026
@coveralls
Copy link

Pull Request Test Coverage Report for Build 21996320244

Details

  • 3 of 7 (42.86%) changed or added relevant lines in 2 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.3%) to 86.97%

Changes Missing Coverage Covered Lines Changed/Added Lines %
internal/pgengine/log_hook.go 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
internal/pgengine/log_hook.go 4 82.88%
Totals Coverage Status
Change from base Build 21996108468: -0.3%
Covered Lines: 1722
Relevant Lines: 1980

💛 - Coveralls

@pashagolub pashagolub requested a review from 0xgouda February 13, 2026 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants