{"record":{"id":"9972b792aa06b3da","repo":"we-promise/sure","slug":"invalid-ibkr-flex-xml-no-flexstatement-nodes-foun","errorCode":null,"errorMessage":"Invalid IBKR Flex XML: no FlexStatement nodes found.","messagePattern":"Invalid IBKR Flex XML: no FlexStatement nodes found\\.","errorType":"exception","errorClass":"IbkrItem::ReportParser::ParseError","httpStatus":null,"severity":"error","filePath":"app/models/ibkr_item/report_parser.rb","lineNumber":38,"sourceCode":"    @document = Nokogiri::XML(xml_body.to_s) { |config| config.strict.noblanks }\n  rescue Nokogiri::XML::SyntaxError => e\n    raise ParseError, \"Invalid IBKR Flex XML: #{e.message}\"\n  end\n\n  def parse\n    validate_document!\n\n    {\n      metadata: root_metadata,\n      accounts: flex_statements.map { |statement| parse_statement(statement) }\n    }\n  end\n\n  private\n\n    def validate_document!\n      raise ParseError, \"Invalid IBKR Flex XML: missing FlexQueryResponse root.\" unless @document.at_xpath(\"//FlexQueryResponse\")\n      raise ParseError, \"Invalid IBKR Flex XML: no FlexStatement nodes found.\" if flex_statements.empty?\n    end\n\n    def flex_statements\n      @document.xpath(\"//FlexStatement\")\n    end\n\n    def root_metadata\n      node_attributes(@document.at_xpath(\"//FlexQueryResponse\"))\n    end\n\n    def parse_statement(statement)\n      statement_data = node_attributes(statement)\n      account_information = node_attributes(statement.at_xpath(\"./AccountInformation\"))\n      position_values = section_rows(statement, POSITION_VALUE_CONTAINER_NAMES, POSITION_VALUE_ROW_NAMES)\n      cash_report = section_rows(statement, CASH_REPORT_CONTAINER_NAMES, CASH_REPORT_ROW_NAMES)\n      equity_summary_in_base = section_rows(statement, EQUITY_SUMMARY_CONTAINER_NAMES, EQUITY_SUMMARY_ROW_NAMES)\n      open_positions = section_rows(statement, OPEN_POSITION_CONTAINER_NAMES, OPEN_POSITION_ROW_NAMES)\n      trades = section_rows(statement, TRADES_CONTAINER_NAMES, TRADE_ROW_NAMES)","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/we-promise/sure/blob/e69894adb92547273377398c15f45c979cd9416a/app/models/ibkr_item/report_parser.rb#L20-L56","documentation":"validate_document! raises when the document has a FlexQueryResponse root but zero //FlexStatement nodes. The envelope is correct but contains no account statements, so there is nothing to import and the parser refuses to return an empty account set as if it were valid.","triggerScenarios":"A Flex report with no FlexStatement elements: a Flex Query configured with no statement-producing sections for the requested date range, or a minimal ack document from IBKR.","commonSituations":"Newly created Flex Queries with no data yet; query date ranges excluding all statements; IBKR occasionally returning empty reports while a new token is still activating (data lag).","solutions":["Verify the Flex Query (query_id) in IBKR Portal includes the statement types and date range you expect","Retry later — Flex report data can lag behind token/query creation","Distinguish this from parse failures when rescuing: an empty-statement document means configuration/timing, not corruption"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"doc = Nokogiri::XML(body)\ndoc.at_xpath('//FlexQueryResponse').present? && doc.xpath('//FlexStatement').any? # both must hold before parse","typeGuard":null,"tryCatchPattern":"rescue IbkrItem::ReportParser::ParseError; the 'no FlexStatement nodes' variant is a configuration/timing issue — verify the Flex Query definition and retry later rather than treating the payload as corrupt","preventionTips":["Confirm the Flex Query includes statement-producing sections for the target date range","Expect empty reports during new-token activation; schedule a delayed retry","Distinguish empty-statement from malformed-XML failures in sync telemetry"],"tags":["ibkr","xml","flex-query","empty-response"],"backgroundTag":"xml-schema-validation-failed","analyzedSha":"e69894adb92547273377398c15f45c979cd9416a","analyzedAt":"2026-08-21T18:22:41.165Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}