Blender V4.3
ErrorHandler.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8#include "ErrorHandler.h"
9#include <iostream>
10
11#include "COLLADASaxFWLIError.h"
12#include "COLLADASaxFWLSaxFWLError.h"
13#include "COLLADASaxFWLSaxParserError.h"
14
15#include "GeneratedSaxParserParserError.h"
16
17#include <cstring>
18
19#include "BLI_utildefines.h"
20
21//--------------------------------------------------------------------
23
24//--------------------------------------------------------------------
25bool ErrorHandler::handleError(const COLLADASaxFWL::IError *error)
26{
27 /* This method must return false when Collada should continue.
28 * See https://github.com/KhronosGroup/OpenCOLLADA/issues/442
29 */
30 bool isError = true;
31 std::string error_context;
32 std::string error_message;
33
34 if (error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXPARSER) {
35 error_context = "Schema validation";
36
37 COLLADASaxFWL::SaxParserError *saxParserError = (COLLADASaxFWL::SaxParserError *)error;
38 const GeneratedSaxParser::ParserError &parserError = saxParserError->getError();
39 error_message = parserError.getErrorMessage();
40
41 if (parserError.getErrorType() ==
42 GeneratedSaxParser::ParserError::ERROR_VALIDATION_MIN_OCCURS_UNMATCHED)
43 {
44 if (STREQ(parserError.getElement(), "effect")) {
45 isError = false;
46 }
47 }
48
49 else if (parserError.getErrorType() ==
50 GeneratedSaxParser::ParserError::
51 ERROR_VALIDATION_SEQUENCE_PREVIOUS_SIBLING_NOT_PRESENT)
52 {
53 if (!(STREQ(parserError.getElement(), "extra") &&
54 STREQ(parserError.getAdditionalText().c_str(), "sibling: fx_profile_abstract")))
55 {
56 isError = false;
57 }
58 }
59
60 else if (parserError.getErrorType() ==
61 GeneratedSaxParser::ParserError::ERROR_COULD_NOT_OPEN_FILE)
62 {
63 isError = true;
64 error_context = "File access";
65 }
66
67 else if (parserError.getErrorType() ==
68 GeneratedSaxParser::ParserError::ERROR_REQUIRED_ATTRIBUTE_MISSING)
69 {
70 isError = true;
71 }
72
73 else {
74 isError = (parserError.getSeverity() !=
75 GeneratedSaxParser::ParserError::Severity::SEVERITY_ERROR_NONCRITICAL);
76 }
77 }
78 else if (error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXFWL) {
79 error_context = "Sax FWL";
80 COLLADASaxFWL::SaxFWLError *saxFWLError = (COLLADASaxFWL::SaxFWLError *)error;
81 error_message = saxFWLError->getErrorMessage();
82
83 /*
84 * Accept non critical errors as warnings (i.e. texture not found)
85 * This makes the importer more graceful, so it now imports what makes sense.
86 */
87
88 isError = (saxFWLError->getSeverity() != COLLADASaxFWL::IError::SEVERITY_ERROR_NONCRITICAL);
89 }
90 else {
91 error_context = "OpenCollada";
92 error_message = error->getFullErrorMessage();
93 isError = true;
94 }
95
96 std::string severity = (isError) ? "Error" : "Warning";
97 std::cout << error_context << " (" << severity << "): " << error_message << std::endl;
98 if (isError) {
99 std::cout << "The Collada import has been forced to stop." << std::endl;
100 std::cout << "Please fix the reported error and then try again.";
101 mError = true;
102 }
103 return isError;
104}
#define STREQ(a, b)
virtual bool handleError(const COLLADASaxFWL::IError *error)
static void error(const char *str)