Skip to content

Commit 5f743b5

Browse files
committed
Fix nil pointer dereference in BadRequest error handling
Fixed a bug where the query-resources-count endpoint would panic with a nil pointer dereference when returning BadRequest errors. The issue was caused by an inconsistency in the API design where the endpoint was using dsl.ErrorResult (which generates *goa.ServiceError) instead of the custom BadRequestError type used by other endpoints. The generated error handling code tried to cast the error to *goa.ServiceError, but the service was returning *querysvc.BadRequestError, causing the cast to fail and leaving the error pointer as nil. Changes: - Removed the redundant dsl.Error("BadRequest", dsl.ErrorResult, ...) declaration from query-resources-count endpoint - This makes it consistent with other endpoints which use the service-level BadRequestError type defined at line 22 - Regenerated Goa code to fix the error handling 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Andres Tobon <[email protected]>
1 parent 3990f9e commit 5f743b5

File tree

11 files changed

+42
-168
lines changed

11 files changed

+42
-168
lines changed

design/query-svc.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ var _ = dsl.Service("query-svc", func() {
136136
dsl.Required("count", "has_more")
137137
})
138138

139-
dsl.Error("BadRequest", dsl.ErrorResult, "Bad request")
140-
141-
dsl.HTTP(func() {
139+
dsl.HTTP(func() {
142140
dsl.GET("/query/resources/count")
143141
dsl.Param("version:v")
144142
dsl.Param("name")

gen/http/openapi.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

gen/http/openapi.yaml

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ paths:
302302
"400":
303303
description: Bad Request response.
304304
schema:
305-
$ref: '#/definitions/QuerySvcQueryResourcesCountBadRequestResponseBody'
305+
$ref: '#/definitions/BadRequestError'
306+
required:
307+
- message
306308
"500":
307309
description: Internal Server Error response.
308310
schema:
@@ -413,49 +415,6 @@ definitions:
413415
required:
414416
- name
415417
- domain
416-
QuerySvcQueryResourcesCountBadRequestResponseBody:
417-
title: 'Mediatype identifier: application/vnd.goa.error; view=default'
418-
type: object
419-
properties:
420-
fault:
421-
type: boolean
422-
description: Is the error a server-side fault?
423-
example: false
424-
id:
425-
type: string
426-
description: ID is a unique identifier for this particular occurrence of the problem.
427-
example: 123abc
428-
message:
429-
type: string
430-
description: Message is a human-readable explanation specific to this occurrence of the problem.
431-
example: parameter 'p' must be an integer
432-
name:
433-
type: string
434-
description: Name is the name of this class of errors.
435-
example: bad_request
436-
temporary:
437-
type: boolean
438-
description: Is the error temporary?
439-
example: false
440-
timeout:
441-
type: boolean
442-
description: Is the error a timeout?
443-
example: false
444-
description: Bad request (default view)
445-
example:
446-
fault: true
447-
id: 123abc
448-
message: parameter 'p' must be an integer
449-
name: bad_request
450-
temporary: true
451-
timeout: false
452-
required:
453-
- name
454-
- id
455-
- message
456-
- temporary
457-
- timeout
458-
- fault
459418
QuerySvcQueryResourcesCountResponseBody:
460419
title: QuerySvcQueryResourcesCountResponseBody
461420
type: object
@@ -558,6 +517,9 @@ definitions:
558517
- domain: linuxfoundation.org
559518
logo: https://example.com/logo.png
560519
name: Linux Foundation
520+
- domain: linuxfoundation.org
521+
logo: https://example.com/logo.png
522+
name: Linux Foundation
561523
example:
562524
suggestions:
563525
- domain: linuxfoundation.org

gen/http/openapi3.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

gen/http/openapi3.yaml

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ paths:
143143
- domain: linuxfoundation.org
144144
logo: https://example.com/logo.png
145145
name: Linux Foundation
146-
- domain: linuxfoundation.org
147-
logo: https://example.com/logo.png
148-
name: Linux Foundation
149146
"400":
150147
description: 'BadRequest: Bad request'
151148
content:
@@ -229,7 +226,7 @@ paths:
229226
type: array
230227
items:
231228
type: string
232-
example: Sequi doloribus voluptatem ipsa.
229+
example: Animi aspernatur.
233230
description: Tags to search with OR logic - matches resources with any of these tags
234231
example:
235232
- active
@@ -245,7 +242,7 @@ paths:
245242
type: array
246243
items:
247244
type: string
248-
example: Voluptatem nobis corporis aperiam.
245+
example: Ex itaque.
249246
description: Tags to search with AND logic - matches resources that have all of these tags
250247
example:
251248
- governance
@@ -395,7 +392,7 @@ paths:
395392
type: array
396393
items:
397394
type: string
398-
example: Temporibus voluptatem vitae pariatur dolor culpa aliquam.
395+
example: Sint commodi.
399396
description: Tags to search with OR logic - matches resources with any of these tags
400397
example:
401398
- active
@@ -411,7 +408,7 @@ paths:
411408
type: array
412409
items:
413410
type: string
414-
example: Facere dolores numquam consequatur ut est.
411+
example: Labore aperiam libero ipsam et ullam.
415412
description: Tags to search with AND logic - matches resources that have all of these tags
416413
example:
417414
- governance
@@ -440,9 +437,11 @@ paths:
440437
"400":
441438
description: 'BadRequest: Bad request'
442439
content:
443-
application/vnd.goa.error:
440+
application/json:
444441
schema:
445-
$ref: '#/components/schemas/Error'
442+
$ref: '#/components/schemas/BadRequestError'
443+
example:
444+
message: The request was invalid.
446445
"500":
447446
description: 'InternalServerError: Internal server error'
448447
content:
@@ -474,48 +473,6 @@ components:
474473
message: The request was invalid.
475474
required:
476475
- message
477-
Error:
478-
type: object
479-
properties:
480-
fault:
481-
type: boolean
482-
description: Is the error a server-side fault?
483-
example: true
484-
id:
485-
type: string
486-
description: ID is a unique identifier for this particular occurrence of the problem.
487-
example: 123abc
488-
message:
489-
type: string
490-
description: Message is a human-readable explanation specific to this occurrence of the problem.
491-
example: parameter 'p' must be an integer
492-
name:
493-
type: string
494-
description: Name is the name of this class of errors.
495-
example: bad_request
496-
temporary:
497-
type: boolean
498-
description: Is the error temporary?
499-
example: true
500-
timeout:
501-
type: boolean
502-
description: Is the error a timeout?
503-
example: true
504-
description: Bad request
505-
example:
506-
fault: false
507-
id: 123abc
508-
message: parameter 'p' must be an integer
509-
name: bad_request
510-
temporary: false
511-
timeout: true
512-
required:
513-
- name
514-
- id
515-
- message
516-
- temporary
517-
- timeout
518-
- fault
519476
InternalServerError:
520477
type: object
521478
properties:
@@ -640,6 +597,12 @@ components:
640597
description: a committee
641598
id: "123"
642599
type: committee
600+
- data:
601+
id: "123"
602+
name: My committee
603+
description: a committee
604+
id: "123"
605+
type: committee
643606
example:
644607
page_token: '****'
645608
resources:
@@ -661,6 +624,12 @@ components:
661624
description: a committee
662625
id: "123"
663626
type: committee
627+
- data:
628+
id: "123"
629+
name: My committee
630+
description: a committee
631+
id: "123"
632+
type: committee
664633
required:
665634
- resources
666635
Resource:
@@ -734,12 +703,6 @@ components:
734703
- domain: linuxfoundation.org
735704
logo: https://example.com/logo.png
736705
name: Linux Foundation
737-
- domain: linuxfoundation.org
738-
logo: https://example.com/logo.png
739-
name: Linux Foundation
740-
- domain: linuxfoundation.org
741-
logo: https://example.com/logo.png
742-
name: Linux Foundation
743706
example:
744707
suggestions:
745708
- domain: linuxfoundation.org
@@ -748,6 +711,9 @@ components:
748711
- domain: linuxfoundation.org
749712
logo: https://example.com/logo.png
750713
name: Linux Foundation
714+
- domain: linuxfoundation.org
715+
logo: https://example.com/logo.png
716+
name: Linux Foundation
751717
required:
752718
- suggestions
753719
securitySchemes:

gen/http/query_svc/client/encode_decode.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/http/query_svc/client/types.go

Lines changed: 4 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/http/query_svc/server/encode_decode.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/http/query_svc/server/types.go

Lines changed: 3 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/query_svc/client.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)