Skip to content

Commit

Permalink
add new causeStackTrace field in exception
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jan 31, 2025
1 parent eaac192 commit c371e9f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ class EventEmitter(

// These exceptions are already logged by Lavaplayer
override fun onTrackException(player: AudioPlayer, track: AudioTrack, exception: FriendlyException) {
val rootCause = getRootCause(exception)

this.player.socketContext.sendMessage(
Message.Serializer,
Message.EmittedEvent.TrackExceptionEvent(
this.player.guildId.toString(),
track.toTrack(audioPlayerManager, pluginInfoModifiers),
Exception(exception.message, exception.severity.toLavalink(), getRootCause(exception).toString())
Exception(exception.message, exception.severity.toLavalink(), rootCause.toString(), rootCause.stackTraceToString())
)
)
}
Expand Down
1 change: 1 addition & 0 deletions LavalinkServer/src/main/java/lavalink/server/util/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ fun FriendlyException.Severity.toLavalink() = when (this) {
fun Exception.Companion.fromFriendlyException(e: FriendlyException) = Exception(
e.message,
Exception.Severity.fromFriendlyException(e.severity),
e.toString(),
e.stackTraceToString()
)

Expand Down
22 changes: 9 additions & 13 deletions docs/api/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ When Lavalink encounters an error, it will respond with a JSON object containing

</details>


## Track API

### Common Types ### {: #track-api-types }
### Common Types ### {: #track-api-types }

#### Track

Expand Down Expand Up @@ -89,16 +88,14 @@ When Lavalink encounters an error, it will respond with a JSON object containing

This endpoint is used to resolve audio tracks for use with the [Update Player](#update-player) endpoint.


!!! tip

Lavalink supports searching via YouTube, YouTube Music, and Soundcloud. To search, you must prefix your identifier with `ytsearch:`, `ytmsearch:` or `scsearch:` respectively.

When a search prefix is used, the returned `loadType` will be `search`. Note that disabling the respective source managers renders these search prefixes useless.

Plugins may also implement prefixes to allow for more search engines to be utilised.


```
GET /v4/loadtracks?identifier=dQw4w9WgXcQ
```
Expand Down Expand Up @@ -203,7 +200,7 @@ Empty object.
```yaml
{
"loadType": "empty",
"data": {}
"data": { }
}
```

Expand All @@ -219,10 +216,11 @@ Empty object.
```yaml
{
"loadType": "error",
"data": {
"data": {
"message": "Something went wrong",
"severity": "fault",
"cause": "..."
"cause": "...",
"causeStackTrace": "...",
}
}
```
Expand Down Expand Up @@ -330,7 +328,7 @@ Array of [Track](#track) objects

## Player API

### Common Types ### {: #player-api-types }
### Common Types ### {: #player-api-types }

#### Player

Expand All @@ -356,7 +354,6 @@ Array of [Track](#track) objects
`sessionId` is provided by the Voice State Update event sent by Discord, whereas the `endpoint` and `token` are provided
with the Voice Server Update. Please refer to https://discord.com/developers/docs/topics/gateway-events#voice


#### Filters

Filters are used in above requests and look like this
Expand Down Expand Up @@ -731,7 +728,7 @@ When `identifier` is used, Lavalink will try to resolve the identifier as a sing
{
"track": {
"encoded": "...",
"identifier": "...",
"identifier": "...",
"userData": { ... }
},
"endTime": 0,
Expand Down Expand Up @@ -781,7 +778,7 @@ Response:
"time": 1500467109,
"position": 60000,
"connected": true,
"ping": 50
"ping": 50
},
"voice": {
"token": "...",
Expand Down Expand Up @@ -1018,7 +1015,6 @@ Response:

Additionally, there are a few REST endpoints for the ip rotation extension.


### Common Types ### {: #route-planner-api-types }

#### Route Planner Types
Expand Down
14 changes: 8 additions & 6 deletions docs/api/websocket.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,12 @@ Dispatched when a track throws an exception.

##### Exception Object

| Field | Type | Description |
|----------|-----------------------|-------------------------------|
| message | ?string | The message of the exception |
| severity | [Severity](#severity) | The severity of the exception |
| cause | string | The cause of the exception |
| Field | Type | Description |
|-----------------|-----------------------|-----------------------------------|
| message | ?string | The message of the exception |
| severity | [Severity](#severity) | The severity of the exception |
| cause | string | The cause of the exception |
| causeStackTrace | string | The full stack trace of the cause |

##### Severity

Expand Down Expand Up @@ -373,7 +374,8 @@ Dispatched when a track throws an exception.
"exception": {
"message": "...",
"severity": "common",
"cause": "..."
"cause": "...",
"causeStackTrace": "..."
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ data class Playlist(
data class Exception(
val message: String?,
val severity: Severity,
val cause: String
val cause: String,
val causeStackTrace: String
) : LoadResult.Data {

/**
Expand Down
4 changes: 3 additions & 1 deletion protocol/src/commonTest/kotlin/LoadResultSerializerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class LoadResultSerializerTest {
"data": {
"message": "The uploader has not made this video available in your country.",
"severity": "common",
"cause": "com.sedmelluq.discord.lavaplayer.tools.FriendlyException: This video is not available in your country."
"cause": "com.sedmelluq.discord.lavaplayer.tools.FriendlyException: This video is not available in your country.",
"causeStackTrace": "com.sedmelluq.discord.lavaplayer.tools.FriendlyException: This video is not available in your country.\n\nblabla"
}
}
""".trimIndent()
Expand All @@ -83,6 +84,7 @@ class LoadResultSerializerTest {
message shouldBe "The uploader has not made this video available in your country."
severity shouldBe Exception.Severity.COMMON
cause shouldBe "com.sedmelluq.discord.lavaplayer.tools.FriendlyException: This video is not available in your country."
causeStackTrace shouldBe "com.sedmelluq.discord.lavaplayer.tools.FriendlyException: This video is not available in your country.\n\nblabla"
}
}
}
Expand Down

0 comments on commit c371e9f

Please sign in to comment.