Conversation
Comment on lines
+353
to
+355
| if (cargo === undefined) { | ||
| throw new Error('Cargo not found on the request. Register the bindingCargo() middleware on this route before calling getCargo().') | ||
| } |
Contributor
There was a problem hiding this comment.
req._cargo가 undefined뿐만 아니라 null일 가능성도 배제할 수 없습니다. 만약 null인 경우 cargo === undefined 조건문을 통과하여 null이 T 타입으로 캐스팅되어 반환되며, 이후 이 객체의 프로퍼티에 접근할 때 런타임 에러(TypeError)가 발생할 수 있습니다.
따라서 cargo === undefined 대신 cargo == null을 사용하여 더 안전하게 방어적 코딩을 적용하는 것이 좋습니다.
Suggested change
| if (cargo === undefined) { | |
| throw new Error('Cargo not found on the request. Register the bindingCargo() middleware on this route before calling getCargo().') | |
| } | |
| if (cargo == null) { | |
| throw new Error('Cargo not found on the request. Register the bindingCargo() middleware on this route before calling getCargo().') | |
| } |
Member
Author
There was a problem hiding this comment.
_cargo 자체가 any 타입의 전략 확장 필드여서 외부에서 접근이 가능하고, 항상 유효한 T를 반환하고, 아니면 예외를 반환하기 위해 요청한 대로 null로 바꿔서 undefined, null 상황을 모두 방지하는 코드로 미리 작성.
laggu
approved these changes
May 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
논의 결과에 따라 getCargo가 undefined를 리턴하지 않도록 수정하고, 만약 bindingCargo가 실행되지 않은 상태로 실행되게 된다면 오류를 반환하도록 수정하였습니다.