Skip to content

Commit

Permalink
Add forbidden error
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko committed Jul 17, 2023
1 parent 9fa2d3f commit 920dceb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/kino/bridge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ defmodule Kino.Bridge do
@doc """
Requests the file path for notebook file with the given name.
"""
@spec get_file_entry_path(String.t()) :: {:ok, term()} | {:error, request_error() | String.t()}
@spec get_file_entry_path(String.t()) ::
{:ok, term()} | {:error, request_error() | :forbidden | String.t()}
def get_file_entry_path(name) do
with {:ok, reply} <- io_request({:livebook_get_file_entry_path, name}), do: reply
end

@doc """
Requests the file spec for notebook file with the given name.
"""
@spec get_file_entry_spec(String.t()) :: {:ok, term()} | {:error, request_error() | String.t()}
@spec get_file_entry_spec(String.t()) ::
{:ok, term()} | {:error, request_error() | :forbidden | String.t()}
def get_file_entry_spec(name) do
with {:ok, reply} <- io_request({:livebook_get_file_entry_spec, name}), do: reply
end
Expand Down
19 changes: 19 additions & 0 deletions lib/kino/fs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ defmodule Kino.FS do
Provides access to notebook files.
"""

defmodule ForbiddenError do
@moduledoc """
Exception raised when access to a notebook file is forbidden.
"""

defexception [:name]

@impl true
def message(exception) do
"forbidden access to file #{inspect(exception.name)}"
end
end

@doc """
Accesses notebook file with the given name and returns a local path
to ead its contents from.
Expand All @@ -24,6 +37,9 @@ defmodule Kino.FS do
{:ok, path} ->
path

{:error, :forbidden} ->
raise ForbiddenError, name: name

{:error, message} when is_binary(message) ->
raise message

Expand Down Expand Up @@ -57,6 +73,9 @@ defmodule Kino.FS do
{:ok, spec} ->
spec

{:error, :forbidden} ->
raise ForbiddenError, name: name

{:error, message} when is_binary(message) ->
raise message

Expand Down

0 comments on commit 920dceb

Please sign in to comment.