Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var (
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.
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.
)

type actionsExceptionError struct {
Expand Down Expand Up @@ -87,12 +91,25 @@ func newRequestResponseError(req *http.Request, resp *http.Response, err error)

switch {
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))
Comment on lines 94 to +101
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.
}
}

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
}
Comment on lines +105 to 117
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.
}
Loading