Blender  V2.93
ErrorHandler.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
20 #include "ErrorHandler.h"
21 #include <iostream>
22 
23 #include "COLLADASaxFWLIError.h"
24 #include "COLLADASaxFWLSaxFWLError.h"
25 #include "COLLADASaxFWLSaxParserError.h"
26 
27 #include "GeneratedSaxParserParserError.h"
28 
29 #include <cstring>
30 
31 #include "BLI_utildefines.h"
32 
33 //--------------------------------------------------------------------
34 ErrorHandler::ErrorHandler() : mError(false)
35 {
36 }
37 
38 //--------------------------------------------------------------------
39 bool ErrorHandler::handleError(const COLLADASaxFWL::IError *error)
40 {
41  /* This method must return false when Collada should continue.
42  * See https://github.com/KhronosGroup/OpenCOLLADA/issues/442
43  */
44  bool isError = true;
45  std::string error_context;
46  std::string error_message;
47 
48  if (error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXPARSER) {
49  error_context = "Schema validation";
50 
51  COLLADASaxFWL::SaxParserError *saxParserError = (COLLADASaxFWL::SaxParserError *)error;
52  const GeneratedSaxParser::ParserError &parserError = saxParserError->getError();
53  error_message = parserError.getErrorMessage();
54 
55  if (parserError.getErrorType() ==
56  GeneratedSaxParser::ParserError::ERROR_VALIDATION_MIN_OCCURS_UNMATCHED) {
57  if (STREQ(parserError.getElement(), "effect")) {
58  isError = false;
59  }
60  }
61 
62  else if (parserError.getErrorType() ==
63  GeneratedSaxParser::ParserError::
64  ERROR_VALIDATION_SEQUENCE_PREVIOUS_SIBLING_NOT_PRESENT) {
65  if (!(STREQ(parserError.getElement(), "extra") &&
66  STREQ(parserError.getAdditionalText().c_str(), "sibling: fx_profile_abstract"))) {
67  isError = false;
68  }
69  }
70 
71  else if (parserError.getErrorType() ==
72  GeneratedSaxParser::ParserError::ERROR_COULD_NOT_OPEN_FILE) {
73  isError = true;
74  error_context = "File access";
75  }
76 
77  else if (parserError.getErrorType() ==
78  GeneratedSaxParser::ParserError::ERROR_REQUIRED_ATTRIBUTE_MISSING) {
79  isError = true;
80  }
81 
82  else {
83  isError = (parserError.getSeverity() !=
84  GeneratedSaxParser::ParserError::Severity::SEVERITY_ERROR_NONCRITICAL);
85  }
86  }
87  else if (error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXFWL) {
88  error_context = "Sax FWL";
89  COLLADASaxFWL::SaxFWLError *saxFWLError = (COLLADASaxFWL::SaxFWLError *)error;
90  error_message = saxFWLError->getErrorMessage();
91 
92  /*
93  * Accept non critical errors as warnings (i.e. texture not found)
94  * This makes the importer more graceful, so it now imports what makes sense.
95  */
96 
97  isError = (saxFWLError->getSeverity() != COLLADASaxFWL::IError::SEVERITY_ERROR_NONCRITICAL);
98  }
99  else {
100  error_context = "OpenCollada";
101  error_message = error->getFullErrorMessage();
102  isError = true;
103  }
104 
105  std::string severity = (isError) ? "Error" : "Warning";
106  std::cout << error_context << " (" << severity << "): " << error_message << std::endl;
107  if (isError) {
108  std::cout << "The Collada import has been forced to stop." << std::endl;
109  std::cout << "Please fix the reported error and then try again.";
110  mError = true;
111  }
112  return isError;
113 }
#define STREQ(a, b)
virtual bool handleError(const COLLADASaxFWL::IError *error)
static void error(const char *str)
Definition: meshlaplacian.c:65