Skip to content

Commit e37a643

Browse files
committed
Improve error message on overlong lines in process.slurp
This wraps the `fs2.text.LineTooLongException` that is thrown by `fs2.text.linesLimited` which is used in `process.slurp` to enrich the error message with more helpful information. Instead of this: ``` 2023-07-19 15:34:45,215 ERROR Steward scala-steward-org/test-repo-1 failed fs2.text$LineTooLongException: Max line size is 50 but 79 chars have been accumulated at fs2.text$.$anonfun$linesImpl$1(text.scala:553) ... ``` we now get this: ``` 2023-07-19 16:02:41,546 ERROR Steward scala-steward-org/test-repo-1 failed org.scalasteward.core.io.process$ProcessLineTooLongException: 'mvn --batch-mode dependency:list -DexcludeTransitive=true' outputted a line longer than 50 chars. If the process executed normally and the buffer size is just too small, you can increase it with the --max-buffer-size command-line option and/or open a pull request in https://github.com/scala-steward-org/scala-steward that increases the default buffer size. [INFO] Scanning for projects... [INFO] [INFO] ----------------------< com.mycompany.app:my-app >---------------------- [INFO] Building my-app 1.0-SNAPSHOT at org.scalasteward.core.io.process$$anonfun$1.applyOrElse(process.scala:69) ... Caused by: fs2.text$LineTooLongException: Max line size is 50 but 65 chars have been accumulated at fs2.text$.$anonfun$linesImpl$1(text.scala:553) ... ``` which includes now * the command that led to the exception * the reason why this exception was raised (outputted line is too long) * guidance how to avoid it * the output of the process before the exception is raised * the original exception This change was motivated by the unhelpful error shown in scala-steward-org/scala-steward-action#505 (comment).
1 parent e034a17 commit e37a643

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

modules/core/src/main/scala/org/scalasteward/core/io/process.scala

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ object process {
6464
val raiseError = F.raiseError[List[String]] _
6565

6666
val result =
67-
readLinesIntoBuffer(process.getInputStream, buffer, maxBufferSize, log).flatMap {
68-
maxSizeExceeded =>
67+
readLinesIntoBuffer(process.getInputStream, buffer, maxBufferSize, log)
68+
.adaptErr { case t: fs2.text.LineTooLongException =>
69+
new ProcessLineTooLongException(args, buffer, maxBufferSize, t)
70+
}
71+
.flatMap { maxSizeExceeded =>
6972
F.blocking(process.waitFor()).flatMap { exitValue =>
7073
if (maxSizeExceeded && !args.slurpOptions(SlurpOption.IgnoreBufferOverflow))
7174
raiseError(new ProcessBufferOverflowException(args, buffer, maxBufferSize))
@@ -74,7 +77,7 @@ object process {
7477
else
7578
raiseError(new ProcessFailedException(args, buffer, exitValue))
7679
}
77-
}
80+
}
7881

7982
val onTimeout = F.blocking(process.destroyForcibly()) >>
8083
raiseError(new ProcessTimedOutException(args, buffer, timeout))
@@ -133,18 +136,32 @@ object process {
133136
.through(fs2.text.utf8.decode)
134137
.through(fs2.text.linesLimited(maxBufferSize))
135138

139+
private val bufferOverflowMessage =
140+
s"If the process executed normally and the buffer size is just too small, you can " +
141+
s"increase it with the --${Cli.name.maxBufferSize} command-line option and/or open " +
142+
s"a pull request in ${org.scalasteward.core.BuildInfo.gitHubUrl} that increases the " +
143+
s"default buffer size."
144+
136145
final class ProcessBufferOverflowException(
137146
args: Args,
138147
buffer: ListBuffer[String],
139148
maxBufferSize: Int
140149
) extends IOException(makeMessage(args, buffer) {
141-
s"outputted more than $maxBufferSize lines. " +
142-
s"If the process executed normally and the buffer size is just too small, you can " +
143-
s"increase it with the --${Cli.name.maxBufferSize} command-line option and/or open " +
144-
s"a pull request in ${org.scalasteward.core.BuildInfo.gitHubUrl} that increases the " +
145-
s"default buffer size."
150+
s"outputted more than $maxBufferSize lines. $bufferOverflowMessage"
146151
})
147152

153+
final class ProcessLineTooLongException(
154+
args: Args,
155+
buffer: ListBuffer[String],
156+
maxBufferSize: Int,
157+
cause: fs2.text.LineTooLongException
158+
) extends IOException(
159+
makeMessage(args, buffer) {
160+
s"outputted a line longer than $maxBufferSize chars. $bufferOverflowMessage"
161+
},
162+
cause
163+
)
164+
148165
final class ProcessFailedException(
149166
args: Args,
150167
buffer: ListBuffer[String],

modules/core/src/test/scala/org/scalasteward/core/io/processTest.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.scalasteward.core.io
22

33
import cats.effect.IO
44
import cats.effect.unsafe.implicits.global
5-
import fs2.text.LineTooLongException
65
import munit.FunSuite
76
import org.scalasteward.core.io.process._
87
import org.scalasteward.core.util.{DateTimeAlg, Nel}
@@ -47,7 +46,7 @@ class processTest extends FunSuite {
4746
test("echo: fail, line length > buffer size") {
4847
val Left(t) =
4948
slurp3(Nel.of("echo", "-n", "123456"), 4, Set.empty).attempt.unsafeRunSync()
50-
assert(clue(t).isInstanceOf[LineTooLongException])
49+
assert(clue(t).isInstanceOf[ProcessLineTooLongException])
5150
}
5251

5352
test("ls: ok") {

0 commit comments

Comments
 (0)