-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: compilation error when no JSON libraries are listed in deps
- Loading branch information
Showing
4 changed files
with
69 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
defmodule Protox.Jason do | ||
@moduledoc false | ||
@behaviour Protox.JsonLibrary | ||
|
||
@impl true | ||
def decode!(iodata) do | ||
try do | ||
Jason.decode!(iodata) | ||
rescue | ||
e in [Jason.DecodeError, Protocol.UndefinedError] -> | ||
reraise Protox.JsonDecodingError.new(Exception.message(e)), __STACKTRACE__ | ||
if Code.ensure_loaded?(Jason) do | ||
@behaviour Protox.JsonLibrary | ||
|
||
@impl true | ||
def decode!(iodata) do | ||
try do | ||
Jason.decode!(iodata) | ||
rescue | ||
e in [Jason.DecodeError, Protocol.UndefinedError] -> | ||
reraise Protox.JsonDecodingError.new(Exception.message(e)), __STACKTRACE__ | ||
end | ||
end | ||
end | ||
|
||
@impl true | ||
def encode!(term) do | ||
try do | ||
Jason.encode_to_iodata!(term) | ||
rescue | ||
e in Jason.EncodeError -> | ||
reraise Protox.JsonEncodingError.new(Exception.message(e)), __STACKTRACE__ | ||
@impl true | ||
def encode!(term) do | ||
try do | ||
Jason.encode_to_iodata!(term) | ||
rescue | ||
e in Jason.EncodeError -> | ||
reraise Protox.JsonEncodingError.new(Exception.message(e)), __STACKTRACE__ | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
defmodule Protox.Poison do | ||
@moduledoc false | ||
@behaviour Protox.JsonLibrary | ||
|
||
@impl true | ||
def decode!(iodata) do | ||
try do | ||
Poison.decode!(iodata) | ||
rescue | ||
e in [Poison.DecodeError, Poison.ParseError] -> | ||
reraise Protox.JsonDecodingError.new(Exception.message(e)), __STACKTRACE__ | ||
if Code.ensure_loaded?(Poison) do | ||
@behaviour Protox.JsonLibrary | ||
|
||
@impl true | ||
def decode!(iodata) do | ||
try do | ||
Poison.decode!(iodata) | ||
rescue | ||
e in [Poison.DecodeError, Poison.ParseError] -> | ||
reraise Protox.JsonDecodingError.new(Exception.message(e)), __STACKTRACE__ | ||
end | ||
end | ||
end | ||
|
||
@impl true | ||
def encode!(term) do | ||
try do | ||
Poison.encode!(term) | ||
rescue | ||
e in Poison.EncodeError -> | ||
reraise Protox.JsonEncodingError.new(Exception.message(e)), __STACKTRACE__ | ||
@impl true | ||
def encode!(term) do | ||
try do | ||
Poison.encode!(term) | ||
rescue | ||
e in Poison.EncodeError -> | ||
reraise Protox.JsonEncodingError.new(Exception.message(e)), __STACKTRACE__ | ||
end | ||
end | ||
end | ||
end |