Skip to content
Merged
44 changes: 42 additions & 2 deletions distribution/lib/Standard/Tableau/0.0.0-dev/src/Hyper_File.enso
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ import project.Hyper_Table.Hyper_Table
import project.Internal.Telemetry

polyglot java import org.enso.tableau.HyperFormat
polyglot java import java.io.File as Java_File
polyglot java import java.io.FileNotFoundException
polyglot java import java.io.IOException
polyglot java import java.io.UncheckedIOException
polyglot java import java.nio.file.AccessDeniedException
polyglot java import java.nio.file.DirectoryNotEmptyException
polyglot java import java.nio.file.FileAlreadyExistsException
polyglot java import java.nio.file.FileSystemException
polyglot java import java.nio.file.NoSuchFileException
polyglot java import java.nio.file.NotDirectoryException

## Represents a Tableau Hyper Extract file.
type Hyper_File
Expand Down Expand Up @@ -41,7 +51,7 @@ type Hyper_File
Returns the list of schemas for the connection within the current database
(or catalog).
schemas : Vector Text
schemas self = File_Error.handle_java_exceptions self.file <|
schemas self = handle_java_exceptions self.file <|
array = HyperFormat.readSchemas self.file.path
Vector.from_polyglot_array array

Expand Down Expand Up @@ -76,7 +86,7 @@ type Hyper_File
@schema (hyper -> make_schema_selector hyper True)
tables : Text -> Vector Hyper_Table
tables self schema:Text=self.schema = if schema == "" then self.tables self.schema else
File_Error.handle_java_exceptions self.file <|
handle_java_exceptions self.file <|
array = case schema of
"*" -> HyperFormat.listTablesAllSchemas self.file.path
_ -> HyperFormat.listTables self.file.path schema
Expand Down Expand Up @@ -134,3 +144,33 @@ Table_Viz_Data.from (that:Hyper_File) =
tables = that.tables.map t->t.table.to_text
if schemas.distinct.length <= 1 then (Table_Viz_Data.GenericGrid [Table_Viz_Header.Link "Table" "Table" "read {{@Table}}"] [tables]) else
(Table_Viz_Data.GenericGrid [Table_Viz_Header.Label "Schema", Table_Viz_Header.Link "Table" "Table" "read {{@Table}} {{@Schema}}"] [schemas, tables])

private wrap_io_exception (file : File | Nothing) io_exception =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

associated_file = case io_exception of
_ : FileSystemException ->
path_from_exception = io_exception.getFile
if path_from_exception.is_nothing then file else
File.new path_from_exception
_ -> file

## If the file is not known, all we can do is throw a generic IO error.
This will only usually matter on stream operations, where there is no relevant file -
and so the exceptions like `NoSuchFileException` should not occur in such context.
But instead of risking a Type_Error, we just throw the more generic IO_Error.
if associated_file.is_nothing then Error.throw (File_Error.IO_Error Nothing "An IO error has occurred: "+io_exception.to_text) else case io_exception of
_ : FileNotFoundException -> Error.throw (File_Error.Not_Found associated_file)
_ : NoSuchFileException -> Error.throw (File_Error.Not_Found associated_file)
_ : FileAlreadyExistsException -> Error.throw (File_Error.Already_Exists associated_file)
_ : AccessDeniedException -> File_Error.access_denied associated_file
_ : DirectoryNotEmptyException -> Error.throw (File_Error.Directory_Not_Empty associated_file)
_ : NotDirectoryException -> Error.throw (File_Error.Not_A_Directory associated_file)
_ -> Error.throw (File_Error.IO_Error associated_file "An IO error has occurred: "+io_exception.to_text)

private handle_java_exceptions (file : File | Nothing) ~action =
handle_io_exception caught_panic =
wrap_io_exception file caught_panic.payload
handle_unchecked_io_exception caught_panic =
wrap_io_exception file caught_panic.payload.getCause
Panic.catch IOException handler=handle_io_exception <|
Panic.catch UncheckedIOException handler=handle_unchecked_io_exception <|
action
Loading