|
1 | 1 | /*
|
2 |
| - * Copyright 2016-2022 DiffPlug |
| 2 | + * Copyright 2016-2023 DiffPlug |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -94,26 +94,34 @@ public void performAction(InputChanges inputs) throws Exception {
|
94 | 94 |
|
95 | 95 | private void processInputFile(@Nullable GitRatchet ratchet, Formatter formatter, File input) throws IOException {
|
96 | 96 | File output = getOutputFile(input);
|
97 |
| - getLogger().debug("Applying format to " + input + " and writing to " + output); |
| 97 | + getLogger().debug("Applying format to {} and writing to {}", input, output); |
98 | 98 | PaddedCell.DirtyState dirtyState;
|
99 | 99 | if (ratchet != null && ratchet.isClean(getProjectDir().get().getAsFile(), getRootTreeSha(), input)) {
|
100 | 100 | dirtyState = PaddedCell.isClean();
|
101 | 101 | } else {
|
102 |
| - dirtyState = PaddedCell.calculateDirtyState(formatter, input); |
| 102 | + try { |
| 103 | + dirtyState = PaddedCell.calculateDirtyState(formatter, input); |
| 104 | + } catch (IOException e) { |
| 105 | + throw new IOException("Issue processing file: " + input, e); |
| 106 | + } catch (RuntimeException e) { |
| 107 | + throw new IllegalArgumentException("Issue processing file: " + input, e); |
| 108 | + } |
103 | 109 | }
|
104 | 110 | if (dirtyState.isClean()) {
|
105 | 111 | // Remove previous output if it exists
|
106 | 112 | Files.deleteIfExists(output.toPath());
|
107 | 113 | } else if (dirtyState.didNotConverge()) {
|
108 |
| - getLogger().warn("Skipping '" + input + "' because it does not converge. Run {@code spotlessDiagnose} to understand why"); |
| 114 | + getLogger().warn("Skipping '{}}' because it does not converge. Run {@code spotlessDiagnose} to understand why", input); |
109 | 115 | } else {
|
110 | 116 | Path parentDir = output.toPath().getParent();
|
111 | 117 | if (parentDir == null) {
|
112 |
| - throw new IllegalStateException("Every file has a parent folder."); |
| 118 | + throw new IllegalStateException("Every file has a parent folder. But not: " + output); |
113 | 119 | }
|
114 | 120 | Files.createDirectories(parentDir);
|
115 | 121 | // Need to copy the original file to the tmp location just to remember the file attributes
|
116 | 122 | Files.copy(input.toPath(), output.toPath(), StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES);
|
| 123 | + |
| 124 | + getLogger().info(String.format("Writing clean file: %s", output)); |
117 | 125 | dirtyState.writeCanonicalTo(output);
|
118 | 126 | }
|
119 | 127 | }
|
|
0 commit comments