Skip to content

Commit 7bea164

Browse files
authored
Merge pull request #3125 from scala-steward-org/topic/wrap-LineTooLongException
Improve error message on overlong lines in `process.slurp`
2 parents e034a17 + e37a643 commit 7bea164

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)