{"record":{"id":"01afb5f44b7f48bd","repo":"prestodb/presto","slug":"warning-as-error-01afb5","errorCode":"WARNING_AS_ERROR","errorMessage":"%s","messagePattern":"%s","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/warnings/DefaultWarningCollector.java","lineNumber":66,"sourceCode":"    @Override\n    public synchronized void add(PrestoWarning warning)\n    {\n        requireNonNull(warning, \"warning is null\");\n        switch (warningHandlingLevel) {\n            case SUPPRESS:\n                break;\n            case NORMAL:\n                addWarningIfNumWarningsLessThanConfig(warning);\n                break;\n            case AS_ERROR:\n                /* Parser warnings must be handled differently since we should not throw an exception when parsing.\n                 * Warnings are collected and an exception with all warnings is thrown in {@link QueryPreparer#prepareQuery}\n                 */\n                if (warning.getWarningCode() == PARSER_WARNING.toWarningCode()) {\n                    addWarningIfNumWarningsLessThanConfig(warning);\n                }\n                else {\n                    throw new PrestoException(WARNING_AS_ERROR, warning.toString());\n                }\n        }\n    }\n\n    @Override\n    public synchronized List<PrestoWarning> getWarnings()\n    {\n        return ImmutableList.copyOf(warnings.values());\n    }\n\n    private synchronized void addWarningIfNumWarningsLessThanConfig(PrestoWarning warning)\n    {\n        if (warnings.size() < config.getMaxWarnings()) {\n            warnings.put(warning.getWarningCode(), warning);\n        }\n    }\n\n    @Override","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/warnings/DefaultWarningCollector.java#L48-L84","documentation":"When the WarningHandlingLevel is AS_ERROR (a session or system warnings-as-errors mode), DefaultWarningCollector.add throws PrestoException(WARNING_AS_ERROR) for any warning other than PARSER_WARNING, converting the first non-parser warning into a hard query failure. The thrown message is the warning's own toString(), so the actual cause is embedded in the exception message. Parser warnings are exempt so QueryPreparer can collect and throw them all at once during prepareQuery.","triggerScenarios":"A query runs with warning handling set to AS_ERROR (session property warning-handling-level=AS_ERROR or system config warning-handling.level=AS_ERROR) and execution emits any non-parser warning - e.g. deprecated connector behavior, Hive metadata warnings, or runtime deprecation notices.","commonSituations":"CI regression gates configured with warnings-as-errors catching a newly emitted deprecation warning after a connector/Presto upgrade; strict production settings where any warning (e.g. orphan-file or metadata warnings) now aborts queries; a plugin emitting a non-parser warning that was previously only informational.","solutions":["Read the exception message - it is warning.toString() - and fix the underlying condition that produced the warning (deprecation, metadata issue, etc.).","Set the session property warning-handling-level=NORMAL to collect warnings instead of failing.","Change the coordinator config warning-handling.level from AS_ERROR to NORMAL if strict mode is not needed cluster-wide.","If a specific plugin/connector emits the offending warning, upgrade or patch it so it uses PARSER_WARNING or stops emitting it."],"exampleFix":"-- before: query fails with WARNING_AS_ERROR\nSET SESSION warning_handling_level = 'AS_ERROR';\nSELECT ...\n\n-- after\nSET SESSION warning_handling_level = 'NORMAL';\nSELECT ...","handlingStrategy":"try-catch","validationCode":"// Before running, ensure the session won't fail on warnings\nString level = session.getSystemProperty(\"warning_handling_level\", String.class);\nif (\"AS_ERROR\".equals(level)) {\n    log.warn(\"Warnings will abort this query; set warning_handling_level=NORMAL to tolerate them\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    queryRunner.execute(query);\n} catch (PrestoException e) {\n    if (e.getErrorCode().getName().equals(\"WARNING_AS_ERROR\")) {\n        // the message contains warning.toString(); log and rerun with NORMAL level\n        log.warn(\"Query aborted by warning-as-errors mode: \" + e.getMessage());\n        return executeWithWarningLevel(query, \"NORMAL\");\n    }\n    throw e;\n}","preventionTips":["Set warning-handling-level=NORMAL except in strict CI/regression pipelines.","Treat WARNING_AS_ERROR messages as actionable: fix the deprecated behavior reported in the message.","After connector/Presto upgrades, run queries in NORMAL mode first to see what warnings appear.","Have plugins emit PARSER_WARNING codes only where intended so AS_ERROR mode skips them."],"tags":["warnings","query-failure","configuration","presto"],"backgroundTag":"warnings-as-errors","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}