Skip to content

Improve error message during JSON unmarshalling #705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2025

Conversation

andrew-farries
Copy link
Collaborator

@andrew-farries andrew-farries commented Mar 3, 2025

When an operation object has multiple keys, like this:

{
  "name": "31_add_constraint",
  "operations": [
    {
      "alter_column": {
        "table": "items",
        "column": "assignee",
        "check": {
          "name": "items_assignee_check",
          "constraint": "assignee IN ('alice', 'bob')"
        }
      },
      "up": "(SELECT CASE WHEN assignee in ('alice', 'bob') THEN assignee ELSE 'alice' END)",
      "down": "assignee"
    }
  ]
}

improve the error message to show the keys that are present in the object.

(Here up and down need to be moved inside alter_column).

Previously, the error messasge was of no use:

Error: reading migration file: invalid migration: map[alter_column:[123 10 32 32 32 32 32 32 32 32 34 116 97 98 108 101 34 58 32 34 105 116 101 109 115 34 44 10 32 32 32 32 32 32 32 32 34 99 111 108 117 109 110 34 58 32 34 97 115 115 105 103 110 101 101 34 44 10 32 32 32 32 32 32 32 32 34 99 104 101 99 107 34 58 32 123 10 32 32 32 32 32 32 32 32 32 32 34 110 97 109 101 34 58 32 34 105 116 101 109 115 95 97 115 115 105 103 110 101 101 95 99 104 101 99 107 34 44 10 32 32 32 32 32 32 32 32 32 32 34 99 111 110 115 116 114 97 105 110 116 34 58 32 34 97 115 115 105 103 110 101 101 32 73 78 32 40 39 97 108 105 99 101 39 44 32 39 98 111 98 39 41 34 10 32 32 32 32 32 32 32 32 125 10 32 32 32 32 32 32 125] down:[34 97 115 115 105 103 110 101 101 34] up:[34 40 83 69 76 69 67 84 32 67 65 83 69 32 87 72 69 78 32 97 115 115 105 103 110 101 101 32 105 110 32 40 39 97 108 105 99 101 39 44 32 39 98 111 98 39 41 32 84 72 69 78 32 97 115 115 105 103 110 101 101 32 69 76 83 69 32 39 97 108 105 99 101 39 32 69 78 68 41 34]]

The new error message is:

Error: reading migration file: multiple keys in operation object at index 0: alter_column, up, down

@github-actions github-actions bot temporarily deployed to Docs Preview March 3, 2025 12:24 Inactive
When an operation object has multiple keys, like this:

```json
{
  "name": "31_add_constraint",
  "operations": [
    {
      "alter_column": {
        "table": "items",
        "column": "assignee",
        "check": {
          "name": "items_assignee_check",
          "constraint": "assignee IN ('alice', 'bob')"
        }
      },
      "up": "(SELECT CASE WHEN assignee in ('alice', 'bob') THEN assignee ELSE 'alice' END)",
      "down": "assignee"
    }
  ]
}
```
(Here `up` and `down` need to be moved inside the `alter_column` value).

Improve the error message to show the keys that are present in the
object.
@github-actions github-actions bot temporarily deployed to Docs Preview March 3, 2025 12:25 Inactive
@andrew-farries andrew-farries marked this pull request as ready for review March 3, 2025 12:31
@andrew-farries andrew-farries requested a review from kvch March 3, 2025 12:31
@andrew-farries andrew-farries merged commit 8043077 into main Mar 3, 2025
29 checks passed
@andrew-farries andrew-farries deleted the better-error-message branch March 3, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants