vitebonus / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

ClosureBuilder: Show file where error occurs #602

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago

- What steps will reproduce the problem?

1. Install the environment (see "What version of the product are you using? On 
what operating system?" below).
2. Follow tutorial "Using ClosureBuilder" at 
https://developers.google.com/closure/library/docs/closurebuilder up to step 
"Calculating dependencies".
3. Execute 
"D:\Projekt\PhpStorm\ClosureTest>closure-library\closure\bin\build\closurebuilde
r.py --root=closure-library\" from the windows command prompt (change 
"D:\Projekt\PhpStorm\ClosureTest" according to your installation)

- What is the expected output? What do you see instead?

The result should be similar to what is described in the tutorial, i.e. 

closure-library/closure/bin/build/closurebuilder.py: Scanning paths...
closure-library/closure/bin/build/closurebuilder.py: 596 sources scanned.
closure-library/closure/bin/build/closurebuilder.py: Building dependency tree..
closure-library/closure/goog/base.js
closure-library/closure/goog/debug/error.js
closure-library/closure/goog/string/string.js
closure-library/closure/goog/asserts/asserts.js
closure-library/closure/goog/array/array.js
closure-library/closure/goog/dom/classes.js
closure-library/closure/goog/object/object.js
closure-library/closure/goog/dom/tagname.js
closure-library/closure/goog/useragent/useragent.js
closure-library/closure/goog/math/size.js
closure-library/closure/goog/math/coordinate.js
closure-library/closure/goog/dom/dom.js

but I get

D:\Projekt\PhpStorm\ClosureTest>closure-library\closure\bin\build\closurebuilder
.py --root=closure-library\
D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\closurebuilder
.py: Scanning paths...
Traceback (most recent call last):
  File "D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\closurebuilder.py", line 262, in <module>
    main()
  File "D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\closurebuilder.py", line 200, in main
    sources.add(_PathSource(js_path))
  File "D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\closurebuilder.py", line 175, in __init__
    super(_PathSource, self).__init__(source.GetFileContents(path))
  File "D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\source.py", line 112, in GetFileContents
    return fileobj.read()
  File "C:\Program Files\Python\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 6586: 
character maps to <undefined>

I understand that some character in some file could not be converted (most 
probably from Unicode to Windows1252). 
But which file was it? It would be absolutely useful to know the file where the 
error occurred. 
After some research (please excuse I am absolutely new to Closure and Python), 
I changed method "GetFileContents" in 
\closure-library\closure\bin\build\source.py from

def GetFileContents(path):
  """Get a file's contents as a string.

  Args:
    path: str, Path to file.

  Returns:
    str, Contents of file.

  Raises:
    IOError: An error occurred opening or reading the file.

  """
  fileobj = open(path)
  try:
    return fileobj.read()
  finally:
    fileobj.close() 

to (see attached file)

def GetFileContents(path):
  """Get a file's contents as a string.

  Args:
    path: str, Path to file.

  Returns:
    str, Contents of file.

  Raises:
    IOError: An error occurred opening or reading the file.

  """
  fileobj = None

  try:
    fileobj = open(path)
    return fileobj.read()

  except Exception as e:
    raise IOError("{0} when opening or reading file {1}: {2}".format(e.__class__.__name__ , path, e))

  finally:
    if fileobj is not None:
        fileobj.close()

Now I get

D:\Projekt\PhpStorm\ClosureTest>closure-library\closure\bin\build\closurebuilder
.py --root=closure-library\
D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\closurebuilder
.py: Scanning paths...
Traceback (most recent call last):
  File "D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\source.py", line 121, in GetFileContents
    return fileobj.read()
  File "C:\Program Files\Python\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 6586: 
character maps to <undefined>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\closurebuilder.py", line 262, in <module>
    main()
  File "D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\closurebuilder.py", line 200, in main
    sources.add(_PathSource(js_path))
  File "D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\closurebuilder.py", line 175, in __init__
    super(_PathSource, self).__init__(source.GetFileContents(path))
  File "D:\Projekt\PhpStorm\ClosureTest\closure-library\closure\bin\build\source.py", line 124, in GetFileContents
    raise IOError("{0} when opening or reading file {1}: {2}".format(e.__class__.__name__ , path, e))
OSError: UnicodeDecodeError when opening or reading file 
closure-library\closure\goog\i18n\datetimepatterns.js: 'charmap' 
codec can't decode byte 0x8f in position 6586: character maps to <undefined>

(Maybe there is a way to suppress the first exception being shown - it is the 
first time at all I get in touch with Python). 
But now I see, there is something wrong in file 
closure-library\closure\goog\i18n\datetimepatterns.js. 
(It seems that somehow there came some illegal characters into 
datetimepatterns.js ... I'll enter a separate issue for that).

- What version of the product are you using? On what operating system?

I am running Windows 7 on a 64bit MacBook Pro. I downloaded newest (as of 
11/10/2013) Closure Library (closure-library-20130212-95c19e7f0f5f.zip) and 
installed newest Python for Windows (python-3.3.2.amd64.msi).

- Please provide any additional information below.

I think the public should benefit from my solution showing the file where the 
error occurred. 
Unfortunately, I am currently additionally struggling with GIT/Subversion 
issues, so I cannot contribute the way described below. 
I would anyway be pleased if someone could check in the changes I propose 
above, so that a broader audience could benefit from it. Thanks.

- Note: we cannot accept patches without the contributor license agreement
being signed. See http://code.google.com/p/closure-
library/wiki/Contributors for more info.

Original issue reported on code.google.com by m...@jochenscharr.de on 10 Nov 2013 at 4:04

Attachments:

GoogleCodeExporter commented 8 years ago
Sorry, what I said in 

- What version of the product are you using? On what operating system?

was wrong. I am not working with downloaded version 
closure-library-20130212-95c19e7f0f5f.zip, but a clone of the current Closure 
Library version (http://code.google.com/p/closure-library/), created using git. 
The rest is correct.

Original comment by m...@jochenscharr.de on 10 Nov 2013 at 10:46

GoogleCodeExporter commented 8 years ago
Same problem here

Original comment by crose...@gmail.com on 19 Dec 2013 at 6:34

GoogleCodeExporter commented 8 years ago
Fixed https://github.com/google/closure-library/issues/31

Original comment by joelt...@google.com on 23 Jul 2015 at 4:26