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::ParseError→Dentaku::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.rb19-28 (calculate! 메서드 내부). 새 rescue 절 3-4 줄 삽입.
tesla: spec/lib/cupix/util/formula_parser_spec.rb#
- What:
describe '#calculate!'블록에 두 개의 example 을 추가한다.Dentaku::Error(예: too many operands 를 유발하는'1 1'또는 division-by-zero'5 / 0'표현식) 가 raise 되면Cupix::Logger.warn이 호출되고Cupix::Logger.error는 호출되지 않는지, 그리고Cupix::Errors::Parameter로 재변환되는지 확인.Dentaku::Error가 아닌StandardError(예:Dentaku::Calculator#evaluate!을allow로StandardErrorraise 하도록 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'추가. RubocopRSpec/ContextWording회피 위해whenprefix 사용 (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.rb에expect(Cupix::Logger).to have_received(:warn)(Dentaku 경로) 와expect(Cupix::Logger).to have_received(:error)(일반 StandardError 경로) 검증이 각각 존재. -
ruby -c lib/cupix/util/formula_parser.rb및ruby -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.