Skip to content

Commit

Permalink
Add support for CodexASTParseFailedErr
Browse files Browse the repository at this point in the history
  • Loading branch information
twavv committed Mar 9, 2021
1 parent 93ddc75 commit bbdc9fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 5 additions & 1 deletion cmd/codex/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ var codexUploadCmd = &cobra.Command{
if parseErr != nil {
_, _ = fmt.Fprintf(os.Stderr, "Failed to parse codex (%d issues):\n", len(parseErr.Errors))
for _, e := range parseErr.Errors {
_, _ = fmt.Fprintf(os.Stderr, " - %s\n (%s at %s)\n", red(e.Message), faint(e.Error), cyan(e.SourcePosition))
_, _ = fmt.Fprintf(os.Stderr, " - %s\n (%s", red(e.Message), faint(e.Error))
if e.SourcePosition != "" {
_, _ = fmt.Fprintf(os.Stderr, " at %s", cyan(e.SourcePosition))
}
_, _ = fmt.Fprintf(os.Stderr, ")\n")
}
os.Exit(1)
}
Expand Down
15 changes: 8 additions & 7 deletions internal/api/upload_codex.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ func (c *Client) UploadCodex(r *UploadCodexRequest) (*UploadCodexResponse, *Code
return nil, nil, err
}
if statusError != nil {
if statusError.error.Error != "MySTParseFailedErr" {
return nil, nil, errors.Errorf("unknown error returned from API: %s", statusError.error.Error)
e := statusError.error.Error
if e == "MySTParseFailedErr" || e == "CodexASTParseFailedErr" {
var parseError CodexParseFailedError
if err := json.Unmarshal(statusError.error.Details, &parseError); err != nil {
return nil, nil, errors.Wrap(err, "failed to unmarshal codex parse error details")
}
return nil, &parseError, nil
}
var parseError CodexParseFailedError
if err := json.Unmarshal(statusError.error.Details, &parseError); err != nil {
return nil, nil, errors.Wrap(err, "failed to unmarshal codex parse error details")
}
return nil, &parseError, nil
return nil, nil, errors.Errorf("unknown error returned from API: %s", statusError.error.Error)
}
resp := &UploadCodexResponse{}
err = res.UnmarshalJson(resp)
Expand Down

0 comments on commit bbdc9fa

Please sign in to comment.