Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronleopold committed Oct 20, 2024
2 parents 90805f9 + 5608b5b commit cf12bfd
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/images/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum CoreError {
#[error("{0}")]
EmailerError(#[from] email::EmailError),
#[error("Query error: {0}")]
QueryError(#[from] prisma_client_rust::queries::QueryError),
QueryError(#[from] Box<prisma_client_rust::QueryError>),
#[error("Invalid query error: {0}")]
InvalidQuery(String),
#[error("Invalid usage of query result, failed to load relation: {0}")]
Expand Down Expand Up @@ -57,3 +57,9 @@ pub enum CoreError {
#[error("An unknown error ocurred: {0}")]
Unknown(String),
}

impl From<prisma_client_rust::QueryError> for CoreError {
fn from(error: prisma_client_rust::QueryError) -> Self {
Self::QueryError(Box::new(error))
}
}
24 changes: 18 additions & 6 deletions core/src/job/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,24 @@ pub enum JobError {
#[error("A task experienced a critical error while executing: {0}")]
TaskFailed(String),
#[error("A query error occurred: {0}")]
QueryError(#[from] prisma_client_rust::QueryError),
QueryError(#[from] Box<prisma_client_rust::QueryError>),
#[error("A file error occurred: {0}")]
FileError(#[from] FileError),
#[error("An unknown error occurred: {0}")]
Unknown(String),
}

impl From<prisma_client_rust::QueryError> for JobError {
fn from(error: prisma_client_rust::QueryError) -> Self {
Self::QueryError(Box::new(error))
}
}

impl From<CoreError> for JobError {
fn from(err: CoreError) -> Self {
match err {
CoreError::QueryError(err) => JobError::QueryError(err),
_ => JobError::Unknown(err.to_string()),
CoreError::QueryError(err) => Self::QueryError(err),
_ => Self::Unknown(err.to_string()),
}
}
}
Expand All @@ -50,16 +56,22 @@ pub enum JobManagerError {
#[error("A job was found which was in a deeply invalid state")]
JobLostError,
#[error("A query error occurred {0}")]
QueryError(#[from] prisma_client_rust::QueryError),
QueryError(#[from] Box<prisma_client_rust::QueryError>),
#[error("An unknown error occurred {0}")]
Unknown(String),
}

impl From<JobError> for JobManagerError {
fn from(job_error: JobError) -> Self {
match job_error {
JobError::QueryError(e) => JobManagerError::QueryError(e),
_ => JobManagerError::Unknown(job_error.to_string()),
JobError::QueryError(e) => Self::QueryError(e),
_ => Self::Unknown(job_error.to_string()),
}
}
}

impl From<prisma_client_rust::QueryError> for JobManagerError {
fn from(error: prisma_client_rust::QueryError) -> Self {
Self::QueryError(Box::new(error))
}
}
8 changes: 7 additions & 1 deletion core/src/opds/v2_0/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub enum OPDSV2Error {
#[error("OPDS feed field was not initialized: {0}")]
MalformedFeed(#[from] UninitializedFieldError),
#[error("A query failed while generated OPDS feed: {0}")]
QueryError(#[from] prisma_client_rust::queries::QueryError),
QueryError(#[from] Box<prisma_client_rust::QueryError>),
#[error("Failed to generate OPDS feed: {0}")]
InternalError(#[from] crate::CoreError),
}
Expand All @@ -25,6 +25,12 @@ impl From<OPDSV2Error> for crate::CoreError {
}
}

impl From<prisma_client_rust::QueryError> for OPDSV2Error {
fn from(error: prisma_client_rust::QueryError) -> Self {
Self::QueryError(Box::new(error))
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
8 changes: 7 additions & 1 deletion crates/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub enum CliError {
#[error("{0}")]
OperationFailed(String),
#[error("{0}")]
QueryError(#[from] QueryError),
QueryError(#[from] Box<QueryError>),
#[error("{0}")]
Unknown(String),
}
Expand All @@ -22,4 +22,10 @@ impl From<CoreError> for CliError {
}
}

impl From<prisma_client_rust::QueryError> for CliError {
fn from(error: prisma_client_rust::QueryError) -> Self {
Self::QueryError(Box::new(error))
}
}

pub type CliResult<T> = Result<T, CliError>;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useDirectoryListing } from '@stump/client'
import { useDirectoryListing, useSDK } from '@stump/client'
import { DirectoryListingFile } from '@stump/sdk'
import React, { useState } from 'react'
import toast from 'react-hot-toast'
Expand All @@ -22,6 +22,7 @@ type Props = {
export default function FileExplorerProvider({ rootPath }: Props) {
const navigate = useNavigate()
const isMobile = useMediaMatch('(max-width: 768px)')
const { sdk } = useSDK()

const [layout, setLayout] = useState<ExplorerLayout>(() => getDefaultLayout())

Expand All @@ -39,7 +40,7 @@ export default function FileExplorerProvider({ rootPath }: Props) {
setPath(entry.path)
} else {
try {
const entity = await getBook(entry.path)
const entity = await getBook(entry.path, sdk)
if (entity) {
navigate(paths.bookOverview(entity.id), {
state: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useSDK } from '@stump/client'
import { Text, ToolTip } from '@stump/components'
import { DirectoryListingFile, Media } from '@stump/sdk'
import React, { useEffect, useMemo, useState } from 'react'
Expand All @@ -13,6 +14,7 @@ type Props = {

export default function FileGridItem({ file }: Props) {
const { name, path, is_directory } = file
const { sdk } = useSDK()

const { onSelect } = useFileExplorerContext()

Expand All @@ -27,7 +29,7 @@ export default function FileGridItem({ file }: Props) {
useEffect(() => {
async function tryGetMedia() {
// Note: This should be cached, so it should be fast
const maybeBook = await getBook(path)
const maybeBook = await getBook(path, sdk)
if (maybeBook) {
setBook(maybeBook)
}
Expand All @@ -36,7 +38,7 @@ export default function FileGridItem({ file }: Props) {
if (!is_directory) {
tryGetMedia()
}
}, [path, is_directory])
}, [path, is_directory, sdk])

return (
<ToolTip content={tooltipName} align="start">
Expand Down

0 comments on commit cf12bfd

Please sign in to comment.