Blender  V3.3
ErrorHandler.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
6 #include "ErrorHandler.h"
7 #include <iostream>
8 
9 #include "COLLADASaxFWLIError.h"
10 #include "COLLADASaxFWLSaxFWLError.h"
11 #include "COLLADASaxFWLSaxParserError.h"
12 
13 #include "GeneratedSaxParserParserError.h"
14 
15 #include <cstring>
16 
17 #include "BLI_utildefines.h"
18 
19 //--------------------------------------------------------------------
20 ErrorHandler::ErrorHandler() : mError(false)
21 {
22 }
23 
24 //--------------------------------------------------------------------
25 bool 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  if (STREQ(parserError.getElement(), "effect")) {
44  isError = false;
45  }
46  }
47 
48  else if (parserError.getErrorType() ==
49  GeneratedSaxParser::ParserError::
50  ERROR_VALIDATION_SEQUENCE_PREVIOUS_SIBLING_NOT_PRESENT) {
51  if (!(STREQ(parserError.getElement(), "extra") &&
52  STREQ(parserError.getAdditionalText().c_str(), "sibling: fx_profile_abstract"))) {
53  isError = false;
54  }
55  }
56 
57  else if (parserError.getErrorType() ==
58  GeneratedSaxParser::ParserError::ERROR_COULD_NOT_OPEN_FILE) {
59  isError = true;
60  error_context = "File access";
61  }
62 
63  else if (parserError.getErrorType() ==
64  GeneratedSaxParser::ParserError::ERROR_REQUIRED_ATTRIBUTE_MISSING) {
65  isError = true;
66  }
67 
68  else {
69  isError = (parserError.getSeverity() !=
70  GeneratedSaxParser::ParserError::Severity::SEVERITY_ERROR_NONCRITICAL);
71  }
72  }
73  else if (error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXFWL) {
74  error_context = "Sax FWL";
75  COLLADASaxFWL::SaxFWLError *saxFWLError = (COLLADASaxFWL::SaxFWLError *)error;
76  error_message = saxFWLError->getErrorMessage();
77 
78  /*
79  * Accept non critical errors as warnings (i.e. texture not found)
80  * This makes the importer more graceful, so it now imports what makes sense.
81  */
82 
83  isError = (saxFWLError->getSeverity() != COLLADASaxFWL::IError::SEVERITY_ERROR_NONCRITICAL);
84  }
85  else {
86  error_context = "OpenCollada";
87  error_message = error->getFullErrorMessage();
88  isError = true;
89  }
90 
91  std::string severity = (isError) ? "Error" : "Warning";
92  std::cout << error_context << " (" << severity << "): " << error_message << std::endl;
93  if (isError) {
94  std::cout << "The Collada import has been forced to stop." << std::endl;
95  std::cout << "Please fix the reported error and then try again.";
96  mError = true;
97  }
98  return isError;
99 }
#define STREQ(a, b)
virtual bool handleError(const COLLADASaxFWL::IError *error)
static void error(const char *str)
Definition: meshlaplacian.c:51