Skip to content

Centralises JobsAPI errors and gRPC error codes#8346

Merged
artursouza merged 8 commits into
dapr:release-1.15from
elena-kolevska:jobserrors
Dec 18, 2024
Merged

Centralises JobsAPI errors and gRPC error codes#8346
artursouza merged 8 commits into
dapr:release-1.15from
elena-kolevska:jobserrors

Conversation

@elena-kolevska

@elena-kolevska elena-kolevska commented Dec 11, 2024

Copy link
Copy Markdown
Contributor

We're in the process of centralising all errors and error codes as much as possible for easier metrics, documentation and general code simplicity.
This PR centralises all the error codes for the Jobs API in a single file where all the errors are defined for easy parsing and docs generation.
In addition, we're adding a gRPC code field to the ErrorCode struct, so we can track all the possible gRPC errors as well.

Task list:

  • Add error codes for the Jobs API
  • Centralise all gRPC error codes
  • Add the description of every error as an inline comment
  • Create a parser script that will convert the errors file into a markdown table for docs. (Will sent as PR in the docs repo, probably)
  • Updates Jobs API to follow Dapr error codes convention. This breaks compatibility with 1.14 because it changes API error codes, but the API is still in Alpha, so this is the time to do it. I checked the SDKs that support this feature and none of them seem to be relying on these codes.

This is how an autogenerated table would look like. No value in the gRPC code field means we don't have a rich gRPC error for that code yet.
Screenshot 2024-12-12 at 15 18 13

@jake-engelberg jake-engelberg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any non-testing usage of NotFound(), NotConfigured(), or IncorrectNegative().

Should we remove them to reduce confusion upon looking through this file?

Signed-off-by: Elena Kolevska <[email protected]>
Signed-off-by: Elena Kolevska <[email protected]>
@elena-kolevska

Copy link
Copy Markdown
Contributor Author

I don't see any non-testing usage of NotFound(), NotConfigured(), or IncorrectNegative().
Should we remove them to reduce confusion upon looking through this file?

Yeah, they're not used. Let's delete them, since we're here. 👍

Comment thread pkg/api/errors/errors.go
Comment on lines -26 to -32
const (
InFixName ReasonSegment = "NAME_"
InFixNegative ReasonSegment = "NEGATIVE_"
PostFixName ReasonSegment = "NAME"
PostFixEmpty ReasonSegment = "EMPTY"
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting because they're not used anywhere.

Comment thread pkg/api/errors/errors.go
Build()
}

func NotConfigured(name string, componentType string, metadata map[string]string, grpcCode codes.Code, httpCode int, legacyTag string, reason string, category errorcodes.Category) error {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting because not used anywhere.

Comment thread pkg/api/errors/errors.go
Build()
}

func IncorrectNegative(name string, metadata map[string]string, reason string, category errorcodes.Category) error {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting because not used anywhere.

Comment on lines -25 to -41
const (
CodePrefixScheduler = "SCHEDULER_" // TODO(Cassie): move this to kit eventually
InFixJob ReasonSegment = "JOB_"
InFixAppID ReasonSegment = "APPID_"
InFixGet ReasonSegment = "GET_"
InFixList ReasonSegment = "LIST_"
InFixDelete ReasonSegment = "DELETE_"
InFixSchedule ReasonSegment = "SCHEDULE_"
PostFixRepeats ReasonSegment = "REPEATS"
PostFixJob ReasonSegment = "JOB"
PostFixJobs ReasonSegment = "JOBS"

MsgScheduleJob = "failed to schedule job"
MsgGetJob = "failed to get job"
MsgListJobs = "failed to list jobs"
MsgDeleteJob = "failed to delete job"
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to pkg/messages/errorcodes/errorcodes.go to align with other error codes

Signed-off-by: Elena Kolevska <[email protected]>
@elena-kolevska elena-kolevska changed the title Centralises JobsAPI errors Centralises JobsAPI errors and gRPC error codes Dec 12, 2024
@elena-kolevska

Copy link
Copy Markdown
Contributor Author

FYI @msfussell

@elena-kolevska
elena-kolevska marked this pull request as ready for review December 12, 2024 15:12
@elena-kolevska
elena-kolevska requested review from a team as code owners December 12, 2024 15:12
@elena-kolevska

Copy link
Copy Markdown
Contributor Author

@jake-engelberg We'll have to update this once your PR gets merged.

Comment thread pkg/messages/errorcodes/errorcodes.go Outdated
CommonMalformedResponse = ErrorCode{"ERR_MALFORMED_RESPONSE", "", CategoryCommon} // Malformed response

// ### Scheduler/Jobs API
SchedulerScheduleJob = ErrorCode{"SCHEDULER_SCHEDULE_JOB", "SCHEDULER_SCHEDULE_JOB", CategoryJob} // Error scheduling job

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is what you are wanting to prefix DAPR_ with - correct?

Suggested change
SchedulerScheduleJob = ErrorCode{"SCHEDULER_SCHEDULE_JOB", "SCHEDULER_SCHEDULE_JOB", CategoryJob} // Error scheduling job
SchedulerScheduleJob = ErrorCode{"SCHEDULER_SCHEDULE_JOB", "DAPR_SCHEDULER_SCHEDULE_JOB", CategoryJob} // Error scheduling job

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly, this requirement comes from the error codes proposal: https://github.com/dapr/proposals/blob/main/20230511-BCIRS-error-handling-codes.md#errorinfo-required.
It's an easy change here, but we need to check if we're still on time to make a change in the sdks, if needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a string check to kit to check if DAPR_ is prefixed and if not to add it to avoid this going forward. This was missed bc the const lives in runtime atm, but all the others live in kit and are prefixed in kit. I think I assumed that prefix was added to the const when I added it to runtime

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since scheduler isn't stable 'yet', my vote would be update this to include the dapr prefix. Elena, could you go ahead with this since you have this PR open?

@elena-kolevska elena-kolevska Dec 12, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely! Now is the right time to change this.

Signed-off-by: Elena Kolevska <[email protected]>

# Conflicts:
#	pkg/messages/errorcodes/errorcodes.go
Signed-off-by: Elena Kolevska <[email protected]>
Comment thread pkg/api/errors/errors.go

This comment was marked as resolved.

This comment was marked as resolved.

@artursouza
artursouza merged commit ff107db into dapr:release-1.15 Dec 18, 2024
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.

5 participants