0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-21 22:22:43 -05:00

🎉 Improve error messages

This commit is contained in:
Alejandro Alonso 2024-12-26 13:02:20 +01:00
parent afe6daba1c
commit 74f6062ffc

View file

@ -42,7 +42,7 @@ pub extern "C" fn init(width: i32, height: i32) {
#[no_mangle]
pub extern "C" fn set_render_options(debug: u32, dpr: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
let render_state = state.render_state();
render_state.set_debug_flags(debug);
@ -59,62 +59,62 @@ pub extern "C" fn set_canvas_background(raw_color: u32) {
#[no_mangle]
pub unsafe extern "C" fn render() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
state.render_all(true);
}
#[no_mangle]
pub unsafe extern "C" fn render_without_cache() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
state.render_all(false);
}
#[no_mangle]
pub unsafe extern "C" fn navigate() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
state.navigate();
}
#[no_mangle]
pub extern "C" fn reset_canvas() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
state.render_state().reset_canvas();
}
#[no_mangle]
pub extern "C" fn resize_viewbox(width: i32, height: i32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
state.resize(width, height);
}
#[no_mangle]
pub extern "C" fn set_view(zoom: f32, x: f32, y: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
state.render_state().viewbox.set_all(zoom, x, y);
}
#[no_mangle]
pub extern "C" fn set_view_zoom(zoom: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
state.render_state().viewbox.set_zoom(zoom);
}
#[no_mangle]
pub extern "C" fn set_view_xy(x: f32, y: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
state.render_state().viewbox.set_pan_xy(x, y);
}
#[no_mangle]
pub extern "C" fn use_shape(a: u32, b: u32, c: u32, d: u32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
let id = uuid_from_u32_quartet(a, b, c, d);
state.use_shape(id);
}
#[no_mangle]
pub unsafe extern "C" fn set_shape_kind_circle() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_kind(Kind::Circle(math::Rect::new_empty()));
@ -123,7 +123,7 @@ pub unsafe extern "C" fn set_shape_kind_circle() {
#[no_mangle]
pub unsafe extern "C" fn set_shape_kind_rect() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_kind(Kind::Rect(math::Rect::new_empty()));
@ -132,7 +132,7 @@ pub unsafe extern "C" fn set_shape_kind_rect() {
#[no_mangle]
pub unsafe extern "C" fn set_shape_kind_path() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
let p = Path::try_from(Vec::new()).unwrap();
shape.set_kind(Kind::Path(p));
@ -141,7 +141,7 @@ pub unsafe extern "C" fn set_shape_kind_path() {
#[no_mangle]
pub extern "C" fn set_shape_selrect(left: f32, top: f32, right: f32, bottom: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_selrect(left, top, right, bottom);
}
@ -149,7 +149,7 @@ pub extern "C" fn set_shape_selrect(left: f32, top: f32, right: f32, bottom: f32
#[no_mangle]
pub unsafe extern "C" fn set_shape_clip_content(clip_content: bool) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_clip(clip_content);
}
@ -157,7 +157,7 @@ pub unsafe extern "C" fn set_shape_clip_content(clip_content: bool) {
#[no_mangle]
pub unsafe extern "C" fn set_shape_rotation(rotation: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_rotation(rotation);
}
@ -165,7 +165,7 @@ pub unsafe extern "C" fn set_shape_rotation(rotation: f32) {
#[no_mangle]
pub extern "C" fn set_shape_transform(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_transform(a, b, c, d, e, f);
}
@ -173,7 +173,7 @@ pub extern "C" fn set_shape_transform(a: f32, b: f32, c: f32, d: f32, e: f32, f:
#[no_mangle]
pub extern "C" fn add_shape_child(a: u32, b: u32, c: u32, d: u32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
let id = uuid_from_u32_quartet(a, b, c, d);
if let Some(shape) = state.current_shape() {
shape.add_child(id);
@ -182,7 +182,7 @@ pub extern "C" fn add_shape_child(a: u32, b: u32, c: u32, d: u32) {
#[no_mangle]
pub extern "C" fn clear_shape_children() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.clear_children();
}
@ -190,7 +190,7 @@ pub extern "C" fn clear_shape_children() {
#[no_mangle]
pub extern "C" fn add_shape_solid_fill(raw_color: u32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
let color = skia::Color::new(raw_color);
shape.add_fill(shapes::Fill::Solid(color));
@ -205,7 +205,7 @@ pub extern "C" fn add_shape_linear_fill(
end_y: f32,
opacity: f32,
) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.add_fill(shapes::Fill::new_linear_gradient(
(start_x, start_y),
@ -224,7 +224,7 @@ pub extern "C" fn add_shape_radial_fill(
opacity: f32,
width: f32,
) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.add_fill(shapes::Fill::new_radial_gradient(
(start_x, start_y),
@ -237,7 +237,7 @@ pub extern "C" fn add_shape_radial_fill(
#[no_mangle]
pub extern "C" fn add_shape_fill_stops(ptr: *mut shapes::RawStopData, n_stops: u32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
let len = n_stops as usize;
@ -254,7 +254,7 @@ pub extern "C" fn add_shape_fill_stops(ptr: *mut shapes::RawStopData, n_stops: u
#[no_mangle]
pub extern "C" fn store_image(a: u32, b: u32, c: u32, d: u32, size: u32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
let id = uuid_from_u32_quartet(a, b, c, d);
unsafe {
@ -272,7 +272,7 @@ pub extern "C" fn store_image(a: u32, b: u32, c: u32, d: u32, size: u32) {
#[no_mangle]
pub extern "C" fn is_image_cached(a: u32, b: u32, c: u32, d: u32) -> bool {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
let id = uuid_from_u32_quartet(a, b, c, d);
state.render_state().has_image(&id)
}
@ -287,7 +287,7 @@ pub extern "C" fn add_shape_image_fill(
width: i32,
height: i32,
) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
let id = uuid_from_u32_quartet(a, b, c, d);
if let Some(shape) = state.current_shape() {
shape.add_fill(shapes::Fill::new_image_fill(
@ -300,7 +300,7 @@ pub extern "C" fn add_shape_image_fill(
#[no_mangle]
pub extern "C" fn clear_shape_fills() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.clear_fills();
}
@ -308,7 +308,7 @@ pub extern "C" fn clear_shape_fills() {
#[no_mangle]
pub extern "C" fn set_shape_blend_mode(mode: i32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_blend_mode(render::BlendMode::from(mode));
}
@ -316,7 +316,7 @@ pub extern "C" fn set_shape_blend_mode(mode: i32) {
#[no_mangle]
pub extern "C" fn set_shape_opacity(opacity: f32) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_opacity(opacity);
}
@ -324,7 +324,7 @@ pub extern "C" fn set_shape_opacity(opacity: f32) {
#[no_mangle]
pub extern "C" fn set_shape_hidden(hidden: bool) {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
shape.set_hidden(hidden);
}
@ -332,7 +332,7 @@ pub extern "C" fn set_shape_hidden(hidden: bool) {
#[no_mangle]
pub extern "C" fn set_shape_path_content() {
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
if let Some(shape) = state.current_shape() {
let bytes = mem::bytes();