@@ -293,54 +293,55 @@ private LockFile(Path path, List<String> inputPackages, List<String> packages) {
293
293
static LockFile fromFile (Path file , BuildToolLog log ) throws IOException {
294
294
List <String > packages = new ArrayList <>();
295
295
List <String > inputPackages = null ;
296
- if (Files .isReadable (file )) {
297
- List <String > lines = Files .readAllLines (file );
298
- if (lines .isEmpty ()) {
299
- throw wrongFormat (file , lines , log );
300
- }
301
- // format:
302
- // 1.) a multiline header comment
303
- // 2.) graalpy version - 1 line (starting with comment #)
304
- // 2.) input packages - 1 line (starting with comment #)
305
- // 3.) locked packages - 1 line each (as input for pip install)
306
- // see also LockFile.write()
307
- Iterator <String > it = lines .iterator ();
308
- try {
309
- // graalpy version, we don't care about it for now, but with future versions the
310
- // file format might change, and we will need to know to parse differently
311
- String graalPyVersion = null ;
312
- while (it .hasNext ()) {
313
- String line = it .next ();
314
- if (line .startsWith (GRAALPY_VERSION_PREFIX )) {
315
- graalPyVersion = line .substring (GRAALPY_VERSION_PREFIX .length ()).trim ();
316
- if (graalPyVersion .isEmpty ()) {
317
- throw wrongFormat (file , lines , log );
318
- }
319
- break ;
320
- }
321
- }
322
- if (graalPyVersion == null ) {
323
- throw wrongFormat (file , lines , log );
324
- }
325
- // input packages
296
+ List <String > lines ;
297
+ try {
298
+ lines = Files .readAllLines (file );
299
+ } catch (IOException e ) {
300
+ throw new IOException (String .format ("Cannot read the lock file from '%s'" , file ), e );
301
+ }
302
+ if (lines .isEmpty ()) {
303
+ throw wrongFormat (file , lines , log );
304
+ }
305
+ // format:
306
+ // 1.) a multiline header comment
307
+ // 2.) graalpy version - 1 line (starting with comment #)
308
+ // 2.) input packages - 1 line (starting with comment #)
309
+ // 3.) locked packages - 1 line each (as input for pip install)
310
+ // see also LockFile.write()
311
+ Iterator <String > it = lines .iterator ();
312
+ try {
313
+ // graalpy version, we don't care about it for now, but with future versions the
314
+ // file format might change, and we will need to know to parse differently
315
+ String graalPyVersion = null ;
316
+ while (it .hasNext ()) {
326
317
String line = it .next ();
327
- if (!line .startsWith (INPUT_PACKAGES_PREFIX )) {
328
- throw wrongFormat (file , lines , log );
329
- }
330
- String pkgs = line .substring (INPUT_PACKAGES_PREFIX .length ()).trim ();
331
- if (pkgs .isEmpty ()) {
332
- throw wrongFormat (file , lines , log );
333
- }
334
- inputPackages = Arrays .asList (pkgs .split (INPUT_PACKAGES_DELIMITER ));
335
- // locked packages
336
- while (it .hasNext ()) {
337
- packages .add (it .next ());
318
+ if (line .startsWith (GRAALPY_VERSION_PREFIX )) {
319
+ graalPyVersion = line .substring (GRAALPY_VERSION_PREFIX .length ()).trim ();
320
+ if (graalPyVersion .isEmpty ()) {
321
+ throw wrongFormat (file , lines , log );
322
+ }
323
+ break ;
338
324
}
339
- } catch (NoSuchElementException e ) {
325
+ }
326
+ if (graalPyVersion == null ) {
340
327
throw wrongFormat (file , lines , log );
341
328
}
342
- } else {
343
- throw new IOException ("can't read lock file" );
329
+ // input packages
330
+ String line = it .next ();
331
+ if (!line .startsWith (INPUT_PACKAGES_PREFIX )) {
332
+ throw wrongFormat (file , lines , log );
333
+ }
334
+ String pkgs = line .substring (INPUT_PACKAGES_PREFIX .length ()).trim ();
335
+ if (pkgs .isEmpty ()) {
336
+ throw wrongFormat (file , lines , log );
337
+ }
338
+ inputPackages = Arrays .asList (pkgs .split (INPUT_PACKAGES_DELIMITER ));
339
+ // locked packages
340
+ while (it .hasNext ()) {
341
+ packages .add (it .next ());
342
+ }
343
+ } catch (NoSuchElementException e ) {
344
+ throw wrongFormat (file , lines , log );
344
345
}
345
346
return new LockFile (file , inputPackages , packages );
346
347
}
@@ -353,7 +354,7 @@ private static IOException wrongFormat(Path file, List<String> lines, BuildToolL
353
354
}
354
355
log .debug ("" );
355
356
}
356
- return new IOException ("invalid lock file format" );
357
+ return new IOException (String . format ( "Cannot read the lock file from '%s' \n (turn on debug log level to see the contents)" , file ) );
357
358
}
358
359
359
360
private static void write (Path venvDirectory , Path lockFile , String lockFileHeader , List <String > inputPackages , String graalPyVersion , BuildToolLog log ) throws IOException {
@@ -836,7 +837,7 @@ private static void lifecycle(BuildToolLog log, String txt, Object... args) {
836
837
}
837
838
838
839
private static void debug (BuildToolLog log , String txt ) {
839
- log .debug (txt );
840
+ log .debug (txt );
840
841
}
841
842
842
843
private static void logDebug (BuildToolLog log , List <String > l , String msg , Object ... args ) {
0 commit comments