Skip to content

Commit

Permalink
Merge branch 'main' into cassandra-key-value-storage-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
irach-ramos authored Oct 11, 2024
2 parents a616ae9 + e998c5f commit 2ad6e13
Show file tree
Hide file tree
Showing 35 changed files with 1,024 additions and 817 deletions.
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ clap = { version = "4.5.4", features = [
"help",
] }
cli-table = "0.4.7"
conditional-trait-gen = "0.4.1"
console-subscriber = "0.3.0"
ctor = "0.2.6"
dashmap = "5.5.3"
Expand Down
16 changes: 8 additions & 8 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ command = "cargo"
args = ["build", "--workspace", "--all-targets"]

[tasks.build-bins-non-ci]
condition = { env_not_set = ["CI"] } # on CI we always 'cargo make build' first so no need to recompile bins
condition = { env_not_set = [
"CI",
] } # on CI we always 'cargo make build' first so no need to recompile bins
run_task = "build-bins"

[tasks.build-bins]
Expand Down Expand Up @@ -106,7 +108,7 @@ command = "cargo"
args = [
"build",
"-p",
"golem-shard-manager", # NOTE: Not all projects are cross-compilable because of an openssl dependency
"golem-shard-manager", # NOTE: Not all projects are cross-compilable because of an openssl dependency
"-p",
"golem-worker-executor",
"-p",
Expand Down Expand Up @@ -322,7 +324,7 @@ args = [
"integration",
"--",
"--nocapture",
"--test-threads=1"
"--test-threads=1",
]

## ** CHECK-OPENAPI **
Expand Down Expand Up @@ -405,10 +407,10 @@ args = ["-v", "./target/golem-service.yaml", "./openapi/golem-service.yaml"]
description = "Publishes packages to crates.io"
dependencies = [
"build-release",
"publish-golem-client",
"publish-golem-api-grpc",
"publish-golem-rib",
"publish-golem-common",
"publish-golem-client",
"publish-golem-service-base",
"publish-golem-test-framework",
"publish-golem-cli",
Expand Down Expand Up @@ -658,9 +660,7 @@ export RUST_BACKTRACE=1

[tasks.check-configs]
description = "Generates configs from code and checks if it's committed"
dependencies = [
"generate-configs"
]
dependencies = ["generate-configs"]

script = '''
git diff --exit-code \
Expand Down Expand Up @@ -694,4 +694,4 @@ docker compose --project-directory log-tools/elastic stop
description = "Stops and removes the elastic environment, including all data"
script = '''
docker compose --project-directory log-tools/elastic down --volumes
'''
'''
2 changes: 1 addition & 1 deletion golem-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ include = ["src/**/*", "Cargo.toml", "build.rs", "openapi/**/*"]
[lib]

[dependencies]
golem-common = { path = "../golem-common" }
golem-common = { path = "../golem-common", version = "0.0.0" }
golem-wasm-ast = { workspace = true }
golem-wasm-rpc = { workspace = true }

Expand Down
26 changes: 26 additions & 0 deletions golem-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;
use std::fmt::{Display, Formatter};

pub mod cache;
pub mod client;
pub mod config;
Expand All @@ -27,3 +30,26 @@ pub mod retries;
pub mod serialization;
pub mod tracing;
pub mod uri;

/// Trait to convert a value to a string which is safe to return through a public API.
pub trait SafeDisplay {
fn to_safe_string(&self) -> String;
}

pub struct SafeString(String);

impl SafeDisplay for SafeString {
fn to_safe_string(&self) -> String {
self.0.clone()
}
}

impl Display for SafeString {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}

pub fn safe(value: String) -> impl SafeDisplay {
SafeString(value)
}
10 changes: 10 additions & 0 deletions golem-common/src/model/component_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use bincode::{Decode, Encode};
use std::fmt::{self, Display, Formatter};

use crate::SafeDisplay;
use golem_wasm_ast::analysis::AnalysedFunctionParameter;
use golem_wasm_ast::core::Mem;
use golem_wasm_ast::metadata::Producers as WasmAstProducers;
Expand Down Expand Up @@ -363,6 +364,15 @@ pub enum ComponentProcessingError {
Analysis(AnalysisFailure),
}

impl SafeDisplay for ComponentProcessingError {
fn to_safe_string(&self) -> String {
match self {
ComponentProcessingError::Parsing(_) => self.to_string(),
ComponentProcessingError::Analysis(_) => self.to_string(),
}
}
}

impl Display for ComponentProcessingError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Expand Down
1 change: 1 addition & 0 deletions golem-component-service-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async-trait = { workspace = true }
bincode = { workspace = true }
bytes = { workspace = true }
chrono = { workspace = true }
conditional-trait-gen = { workspace = true }
http_02 = { workspace = true }
prost = { workspace = true }
prost-types = { workspace = true }
Expand Down
21 changes: 16 additions & 5 deletions golem-component-service-base/src/api/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,40 @@ mod conversion {
use crate::service::component;
use golem_api_grpc::proto::golem::common::{ErrorBody, ErrorsBody};
use golem_api_grpc::proto::golem::component::v1::{component_error, ComponentError};
use golem_common::SafeDisplay;

impl From<component::ComponentError> for ComponentError {
fn from(value: component::ComponentError) -> Self {
let error = match value {
component::ComponentError::AlreadyExists(_) => {
component_error::Error::AlreadyExists(ErrorBody {
error: value.to_string(),
error: value.to_safe_string(),
})
}
component::ComponentError::UnknownComponentId(_)
| component::ComponentError::UnknownVersionedComponentId(_) => {
component_error::Error::NotFound(ErrorBody {
error: value.to_string(),
error: value.to_safe_string(),
})
}
component::ComponentError::ComponentProcessingError(error) => {
component_error::Error::BadRequest(ErrorsBody {
errors: vec![error.to_string()],
errors: vec![error.to_safe_string()],
})
}
component::ComponentError::Internal(error) => {
component::ComponentError::InternalRepoError(_) => {
component_error::Error::InternalError(ErrorBody {
error: error.to_string(),
error: value.to_safe_string(),
})
}
component::ComponentError::InternalConversionError { .. } => {
component_error::Error::InternalError(ErrorBody {
error: value.to_safe_string(),
})
}
component::ComponentError::ComponentStoreError { .. } => {
component_error::Error::InternalError(ErrorBody {
error: value.to_safe_string(),
})
}
};
Expand Down
Loading

0 comments on commit 2ad6e13

Please sign in to comment.