fix(be): fix msg error for check & judge amqpService#3574
Conversation
…tion for undefined msg case
There was a problem hiding this comment.
Pull request overview
Updates the backend AMQP subscriber implementations to align with the updated @golevelup/nestjs-rabbitmq createSubscriber handler typings, and adds explicit handling for undefined message payloads in judge/check consumers.
Changes:
- Adds
createSubscriber<object>()generics and updates handler signatures tomsg: T | undefinedandrawMessage?: ConsumeMessage. - Introduces Nack handling when
msgis undefined for both judge and check subscribers. - Uses optional access for AMQP message properties to match the library’s updated optional parameter typing.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request improves type safety in the AMQP services by replacing 'any' with 'ConsumeMessage' and adding generic types to subscribers. It also adds validation for empty messages in both JudgeAMQPService and CheckAMQPService. The reviewer pointed out that using the default 'Nack()' for empty messages causes infinite requeues and suggested using 'Nack(false)' to prevent poison message loops.
…om/skkuding/codedang into t2715-fix-msg-type-in-amqp-service
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the AMQP services (JudgeAMQPService and CheckAMQPService) to use explicit subscriber handlers, add type safety, and perform basic message validation. The code review feedback highlights several improvement opportunities: first, optional chaining is missing when accessing raw.properties.type, which could lead to runtime errors; second, there is redundant optional chaining inside the check message handler block; and finally, both services suffer from duplicate error logging because errors are already caught and logged inside the individual message handlers before being rethrown.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the AMQP subscription handlers in JudgeAMQPService and CheckAMQPService to use explicit SubscriberHandler types and adds checks for empty messages. However, the refactoring removed error logging inside the catch blocks, which now only return Nack(false). It is recommended to restore error logging in both services to ensure that unexpected failures can be properly debugged and monitored.
| } catch { | ||
| return new Nack(false) | ||
| } |
There was a problem hiding this comment.
CheckAMQPService애서더 마찬가지러 애기처 모탄 때러가 발생해슬 때 때러 로그러ᄱ 남겨더지 간고 단센하개 Nack(false)만 반헌하더로개 수정하거 이스너다.\n\n자애 발생 시 디버거ᄵᆼ걔 모니터링아 위해 catch (error)러ᄱ 터개 때러 로그러ᄱ 기러하더로개 수정하너개 을 건장하너다.
} catch (error) {
this.logger.error(error, 'Unexpected error in check message handler')
return new Nack(false)
}|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the AMQP subscription handlers by introducing the SubscriberHandler type, validating empty messages, and updating error handling to return Nack(false). However, the updated error handling blocks catch exceptions without logging them, which will make debugging and production monitoring difficult. It is recommended to restore error logging before returning Nack(false) in both handleJudgeMessage and handleCheckMessage.
| } catch { | ||
| return new Nack(false) | ||
| } |
| } catch { | ||
| return new Nack(false) | ||
| } |
Description
@golevelup/nestjs-rabbitmq 라이브러리 업데이트로 createSubscriber 타입 정의가 변경되어 기존 check & judge AMQP Service에 적용했습니다.
현재 라이브러리 타입 정의
구체적인 변경사항
createSubscriber<object>()제네릭을 추가해, subscriber가 정상적으로 수신하는 메시지의 payload 타입을object로 명시했습니다.- JudgeAMQPService의 메시지 properties에 접근 시 optional chaining하도록 수정했습니다.(전 커밋에 올렸던
raw?: ConsumeMessage로 타입을 명시하는 방식은 백엔드와 직접 Dependency가 아닌 amqplib를 import해야 해서, pnpm 환경에서 빌드가 깨질 수 있다고 해 이렇게 다시 변경했습니다)msg,raw가 undefined인 경우, check에서는msg가 undefined인 경우 예외를 logging 하고 Nack 처리하도록 추가했습니다. (런타임에서 undefined가 될 경우가 사실상 없지만, 타입 체크할때부터 이런 케이스는 다 막아놨다는 의도가 보이도록 추가해놓기로 결정했습니다.)