Skip to content

Commit

Permalink
Add scalafmt (#179)
Browse files Browse the repository at this point in the history
Nothing changes besides codes been formatted.

I copied `.scalafmt` from mill and did very little tunings for
consistency and readability.

My local test results

```sh
$ ./mill -i __.publishArtifacts + __.test

[418/420] requests[2.13.15].test.test
[418] 
[420/420] requests[3.3.4].test.test
[420] 
[417/420] requests[2.12.20].test.test
[417] 
[420/420] ==================================================================== __.publishArtifacts + __.test ======================================================================= 1s
```

My local binary compatibility check results

```
$ ./mill -i __.mimaReportBinaryIssues
[build.mill-64/68] compile
[build.mill-64] [info] compiling 1 Scala source to /home/lqhuang/Git/requests-scala/out/mill-build/compile.dest/classes ...
[build.mill-64] [info] done compiling
[211/212] requests.jvm[2.12.20].mimaReportBinaryIssues
[210/212] requests.jvm[2.13.15].mimaReportBinaryIssues
[212/212] requests.jvm[3.3.4].mimaReportBinaryIssues
[211] Scanning binary compatibility in /home/lqhuang/Git/requests-scala/out/requests/jvm/2.12.20/compile.dest/classes ...
[210] Scanning binary compatibility in /home/lqhuang/Git/requests-scala/out/requests/jvm/2.13.15/compile.dest/classes ...
[212] Scanning binary compatibility in /home/lqhuang/Git/requests-scala/out/requests/jvm/3.3.4/compile.dest/classes ...
[210] Binary compatibility check passed
[211] Binary compatibility check passed
[212] Binary compatibility check passed
[212/212] ============================== __.mimaReportBinaryIssues ============================== 8s
```
  • Loading branch information
lqhuang authored Jan 8, 2025
1 parent 6f566e6 commit 6047541
Show file tree
Hide file tree
Showing 17 changed files with 595 additions and 482 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
target/
*.iml
.idea
.idea/
.vscode/
.settings
.classpath
.project
.cache
.sbtserver
.scala-build/
project/.sbtserver
tags
nohup.out
Expand Down
12 changes: 12 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version = "3.8.3"

maxColumn = 100
runner.dialect = scala213

newlines.beforeCurlyLambdaParams = multilineWithCaseOnly
rewrite.trailingCommas.style = always

assumeStandardLibraryStripMargin = true
docstrings.style = Asterisk

project.git = true
3 changes: 2 additions & 1 deletion build.mill
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package build

import mill._
import mill.scalalib._
import scalalib._
import scalanativelib._
import mill.scalalib.publish.{Developer, License, PomSettings, VersionControl}

import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.1`
Expand Down
27 changes: 19 additions & 8 deletions requests/src/requests/Exceptions.scala
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package requests

// base class for all custom exceptions thrown by requests.
class RequestsException(val message: String, val cause: Option[Throwable] = None) extends Exception(message, cause.getOrElse(null))
class RequestsException(
val message: String,
val cause: Option[Throwable] = None,
) extends Exception(message, cause.getOrElse(null))

class TimeoutException(val url: String, val readTimeout: Int, val connectTimeout: Int)
extends RequestsException(s"Request to $url timed out. (readTimeout: $readTimeout, connectTimout: $connectTimeout)")
class TimeoutException(
val url: String,
val readTimeout: Int,
val connectTimeout: Int,
) extends RequestsException(
s"Request to $url timed out. (readTimeout: $readTimeout, connectTimout: $connectTimeout)",
)

class UnknownHostException(val url: String, val host: String)
extends RequestsException(s"Unknown host $host in url $url")
extends RequestsException(s"Unknown host $host in url $url")

class InvalidCertException(val url: String, cause: Throwable)
extends RequestsException(s"Unable to validate SSL certificates for $url", Some(cause))
extends RequestsException(
s"Unable to validate SSL certificates for $url",
Some(cause),
)

class RequestFailedException(val response: Response)
extends RequestsException(
s"Request to ${response.url} failed with status code ${response.statusCode}\n${response.text()}"
)
extends RequestsException(
s"Request to ${response.url} failed with status code ${response.statusCode}\n${response.text()}",
)
Loading

0 comments on commit 6047541

Please sign in to comment.