ES /docs

Invalid Formula: Dentaku::AST::Multiplication has too many operands (given 3, expected 2)

Fix Plan: Invalid Formula: Dentaku parse errors logged at error level

Changes#

tesla: lib/cupix/util/formula_parser.rb#

  • What: Cupix::Util::FormulaParser.calculate!rescue StandardError => e 절 앞에 rescue Dentaku::Error, Dentaku::ZeroDivisionError => e 절을 추가한다. 새 절은 Cupix::Logger.warn("Invalid Formula: #{e.message}", class: self.name, function: __method__, formula: expression) 로 로깅한 뒤 기존과 동일하게 Cupix::Errors::Parameter.new(code: 'ARG10001', reason: "Invalid Formula: #{e.message}") 를 raise 한다. 기존 rescue StandardError 절과 그 안의 Cupix::Logger.error 호출은 그대로 유지하여 Dentaku 계열이 아닌 예외(시스템/무결성 오류)는 계속 error 레벨로 로깅한다.
  • Why: RCA 상 이번 사건은 사용자 formula 문법 오류(Dentaku::AST::Multiplication has too many operands = Dentaku::ParseErrorDentaku::Error < StandardError)이며, 서버는 ARG10001 로 정상 400 을 반환했다. Dentaku 는 사용자 입력 검증 실패 시 Dentaku::Error 및 그 하위 클래스(ParseError, TokenizerError, NodeError, ArgumentError, MathDomainError, UnboundVariableError)와 Dentaku::ZeroDivisionError(< ::ZeroDivisionError) 를 raise 한다. 이들은 모두 사용자 입력 오류이므로 warn 이 적절하다. MEMORY.md 원칙("Scope warn-level downgrades to the specific exception class")과 선례(79f45086/TSLA-13689, 27e43020, 6366fb77, d1240f1d, cc2e2887, 2c20f518) 에 따라 넓은 rescue StandardError 는 유지하되 Dentaku 문법 오류만 downgrade.
  • Lines: lib/cupix/util/formula_parser.rb 19-28 (calculate! 메서드 내부). 새 rescue 절 3-4 줄 삽입.

tesla: spec/lib/cupix/util/formula_parser_spec.rb#

  • What: describe '#calculate!' 블록에 두 개의 example 을 추가한다.
    1. Dentaku::Error (예: too many operands 를 유발하는 '1 1' 또는 division-by-zero '5 / 0' 표현식) 가 raise 되면 Cupix::Logger.warn 이 호출되고 Cupix::Logger.error 는 호출되지 않는지, 그리고 Cupix::Errors::Parameter 로 재변환되는지 확인.
    2. Dentaku::Error 가 아닌 StandardError (예: Dentaku::Calculator#evaluate!allowStandardError raise 하도록 stub) 경로에서는 Cupix::Logger.error 가 여전히 호출되고 warn 은 호출되지 않는지 회귀 검증.
  • Why: MEMORY.md 원칙("When narrowing a rescue, update the spec to raise the exact class"). Spec 이 정확한 예외 클래스를 raise 하지 않으면 좁혀진 rescue 를 놓치고 silent 통과할 수 있음. 선례 79f45086 도 동일한 pair (warn/error) example 추가.
  • Lines: 기존 describe '#calculate!' 블록 내부에 신규 context 'when Dentaku raises a parse error'context 'when a non-Dentaku StandardError is raised' 추가. Rubocop RSpec/ContextWording 회피 위해 when prefix 사용 (memory: 79f45086 lesson).

Acceptance Criteria#

  • git diff lib/cupix/util/formula_parser.rb 결과가 rescue Dentaku::Error 절을 새로 추가하고 Cupix::Logger.warn 을 사용함을 보여준다.
  • git diff lib/cupix/util/formula_parser.rb 상 기존 rescue StandardError => e 블록과 그 안의 Cupix::Logger.error("Invalid Formula: ...") 호출이 그대로 유지된다.
  • grep -n 'rescue Dentaku::Error' lib/cupix/util/formula_parser.rb 결과가 1건.
  • spec/lib/cupix/util/formula_parser_spec.rbexpect(Cupix::Logger).to have_received(:warn) (Dentaku 경로) 와 expect(Cupix::Logger).to have_received(:error) (일반 StandardError 경로) 검증이 각각 존재.
  • ruby -c lib/cupix/util/formula_parser.rbruby -c spec/lib/cupix/util/formula_parser_spec.rb 구문 오류 없음.

Tests#

  • 기존 테스트: spec/lib/cupix/util/formula_parser_spec.rb — 특히 describe '#validate!' 의 3개 "when invalid formula" example (bracket / operator / operands & operators) 은 여전히 Cupix::Errors::Parameter 를 raise 해야 함(regression 방지).
  • 신규 테스트: 위 Changes 항목 2에서 명시한 warn/error 페어 example.