Skip to content

Add top level errors conforming to http codes#86

Open
nikola-jokic wants to merge 3 commits intomainfrom
nikola-jokic/add-top-level-error
Open

Add top level errors conforming to http codes#86
nikola-jokic wants to merge 3 commits intomainfrom
nikola-jokic/add-top-level-error

Conversation

@nikola-jokic
Copy link
Copy Markdown
Collaborator

This PR can help diagnose bad requests, or not found responses, allowing easier inspection of misconfigurations, since status codes carry useful pieces of information.

@nikola-jokic nikola-jokic marked this pull request as ready for review April 29, 2026 12:17
@nikola-jokic nikola-jokic requested a review from a team as a code owner April 29, 2026 12:17
Copilot AI review requested due to automatic review settings April 29, 2026 12:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds top-level sentinel errors representing key HTTP status classes to make client-side diagnosis of 400/401/404 responses easier.

Changes:

  • Introduces new exported sentinel errors for HTTP 400/401/404.
  • Wraps actions-exception-derived errors with a status-based top-level error.
  • Adds wrapResponseErrorType helper to apply status-to-sentinel mapping.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread errors.go
RunnerExistsError = scalesetError("runner exists")
JobStillRunningError = scalesetError("job still running")
MessageQueueTokenExpiredError = scalesetError("message queue token expired")
// Top level errors carying the http status code meanings.
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

Typo/grammar in the new comment: "carying" -> "carrying", and "http" should be "HTTP" (also consider "Top-level").

Suggested change
// Top level errors carying the http status code meanings.
// Top-level errors carrying the HTTP status code meanings.

Copilot uses AI. Check for mistakes.
Comment thread errors.go Outdated
Comment on lines +24 to +26
BadRequest = scalesetError("bad request")
NotFound = scalesetError("not found")
Unauthorized = scalesetError("unauthorized")
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

New exported sentinel errors are named inconsistently with the existing *Error pattern in this file (RunnerNotFoundError, RunnerExistsError, etc.). Consider renaming these to BadRequestError, NotFoundError, and UnauthorizedError (or another consistent suffix) to avoid ambiguous/generic exported identifiers like NotFound.

Copilot uses AI. Check for mistakes.
Comment thread errors.go
Comment on lines 93 to +100
case strings.Contains(exception.ExceptionName, "AgentExistsException"):
return fmt.Errorf("%s: %w: %s", sb.String(), RunnerExistsError, exception.Message)
return wrapResponseErrorType(resp, fmt.Errorf("%s: %w: %s", sb.String(), RunnerExistsError, exception.Message))
case strings.Contains(exception.ExceptionName, "AgentNotFoundException"):
return fmt.Errorf("%s: %w: %s", sb.String(), RunnerNotFoundError, exception.Message)
return wrapResponseErrorType(resp, fmt.Errorf("%s: %w: %s", sb.String(), RunnerNotFoundError, exception.Message))
case strings.Contains(exception.ExceptionName, "JobStillRunningException"):
return fmt.Errorf("%s: %w: %s", sb.String(), JobStillRunningError, exception.Message)
return wrapResponseErrorType(resp, fmt.Errorf("%s: %w: %s", sb.String(), JobStillRunningError, exception.Message))
default:
return fmt.Errorf("%s: %w: %w", sb.String(), err, exception)
return wrapResponseErrorType(resp, fmt.Errorf("%s: %w: %w", sb.String(), err, exception))
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

wrapResponseErrorType is only applied in the JSON actions-exception branch. Other newRequestResponseError return paths for the same HTTP responses (e.g., text/plain bodies, empty bodies, read failures, JSON unmarshal failures) will not get the new top-level HTTP status sentinel errors, which seems to undercut the stated goal of diagnosing 400/401/404 via status-based errors. Consider wrapping those earlier returns too (or restructuring to build the error first and apply wrapResponseErrorType once before returning).

Copilot uses AI. Check for mistakes.
Comment thread errors.go
Comment on lines +104 to 114
func wrapResponseErrorType(resp *http.Response, err error) error {
switch resp.StatusCode {
case http.StatusBadRequest:
return fmt.Errorf("%w: %w", BadRequest, err)
case http.StatusUnauthorized:
return fmt.Errorf("%w: %w", Unauthorized, err)
case http.StatusNotFound:
return fmt.Errorf("%w: %w", NotFound, err)
default:
return err
}
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

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

The new status-to-sentinel mapping in wrapResponseErrorType isn’t covered by tests. Since this repo already has comprehensive unit tests for newRequestResponseError in errors_test.go, please add assertions that 400/401/404 responses produce errors where errors.Is(err, BadRequest/Unauthorized/NotFound) is true (including at least one case for each status).

Copilot uses AI. Check for mistakes.
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