Browse Source

Log the ColladaLoader error content more clearly

Garrett Johnson 6 years ago
parent
commit
413391923f
1 changed files with 41 additions and 1 deletions
  1. 41 1
      examples/js/loaders/ColladaLoader.js

+ 41 - 1
examples/js/loaders/ColladaLoader.js

@@ -3814,6 +3814,32 @@ THREE.ColladaLoader.prototype = {
 
 
 		}
 		}
 
 
+		// convert the parser error element into text with each child elements text
+		// separated by new lines.
+		function parserErrorToText( parserError ) {
+
+			var result = '';
+			var stack = [ parserError ];
+			while ( stack.length ) {
+
+				var node = stack.shift();
+				if ( node.nodeType === Node.TEXT_NODE ) {
+
+					result += node.textContent;
+
+				} else {
+
+					result += '\n';
+					stack.push.apply( stack, node.childNodes );
+
+				}
+
+			}
+
+			return result.trim();
+
+		}
+
 		if ( text.length === 0 ) {
 		if ( text.length === 0 ) {
 
 
 			return { scene: new THREE.Scene() };
 			return { scene: new THREE.Scene() };
@@ -3827,7 +3853,21 @@ THREE.ColladaLoader.prototype = {
 		var parserError = xml.getElementsByTagName( 'parsererror' )[ 0 ];
 		var parserError = xml.getElementsByTagName( 'parsererror' )[ 0 ];
 		if ( parserError !== undefined ) {
 		if ( parserError !== undefined ) {
 
 
-			console.error( 'ColladaLoader: Failed to parse collada file.', parserError );
+			// Chrome will return parser error with a div in it
+			var errorElement = getElementsByTagName( parserError, 'div' )[ 0 ];
+			var errorText;
+			if ( errorElement ) {
+
+				errorText = errorElement.textContent;
+
+			} else {
+
+				errorText = parserErrorToText( parserError );
+
+			}
+
+			console.error( 'ColladaLoader: Failed to parse collada file.\n', errorText );
+
 			return null;
 			return null;
 
 
 		}
 		}