Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch 5813 and avoid crash #6585

Merged
merged 3 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/gui/view/documentation/src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,29 @@ fn svg_icon(content: &'static str) -> impl Render {
/// Render entry documentation to HTML code with Tailwind CSS styles.
#[profile(Detail)]
pub fn render(docs: EntryDocumentation) -> String {
match docs {
let html = match docs {
EntryDocumentation::Placeholder(placeholder) => match placeholder {
Placeholder::NoDocumentation => String::from("No documentation available."),
Placeholder::VirtualComponentGroup { name } =>
render_virtual_component_group_docs(name),
},
EntryDocumentation::Docs(docs) => render_documentation(docs),
};
match validate_utf8(&html) {
Ok(_) => html,
Err(_) => {
error!("Internal error. Generated HTML is not valid utf-8. This is bug #5813.");
String::from("Failed to load documentation.")
}
}
}

#[profile(Debug)]
fn validate_utf8(s: &str) -> Result<&str, std::str::Utf8Error> {
let bytes = s.as_bytes();
std::str::from_utf8(bytes)
}

fn render_documentation(docs: Documentation) -> String {
match docs {
Documentation::Module(module_docs) => render_module_documentation(&module_docs, None),
Expand Down
20 changes: 2 additions & 18 deletions app/gui/view/documentation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,12 @@
//! [`Tailwind CSS`]: https://tailwindcss.com/

// === Features ===
#![feature(associated_type_bounds)]
#![feature(associated_type_defaults)]
#![feature(drain_filter)]
#![feature(fn_traits)]
#![feature(option_result_contains)]
#![feature(specialization)]
#![feature(trait_alias)]
#![feature(type_alias_impl_trait)]
#![feature(unboxed_closures)]
// === Standard Linter Configuration ===
#![deny(non_ascii_idents)]
#![warn(unsafe_code)]
#![allow(clippy::bool_to_int_with_if)]
#![allow(clippy::let_and_return)]
#![allow(incomplete_features)] // To be removed, see: https://github.com/enso-org/ide/issues/1559
#![warn(missing_copy_implementations)]
#![warn(missing_debug_implementations)]
#![warn(missing_docs)]
Expand Down Expand Up @@ -64,10 +55,8 @@ use ensogl::Animation;
use ensogl_component::shadow;
use ensogl_derive_theme::FromTheme;
use ensogl_hardcoded_theme::application::component_browser::documentation as theme;
use web::Closure;
use web::HtmlElement;
use web::JsCast;
use web::MouseEvent;

pub mod html;

Expand All @@ -89,6 +78,7 @@ const MIN_CAPTION_HEIGHT: f32 = 1.0;
/// Delay before updating the displayed documentation.
const DISPLAY_DELAY_MS: i32 = 0;


// === Style ===

#[derive(Debug, Clone, Copy, Default, FromTheme)]
Expand All @@ -108,8 +98,6 @@ pub struct Style {
// === Model ===
// =============

type CodeCopyClosure = Closure<dyn FnMut(MouseEvent)>;

/// Model of Native visualization that generates documentation for given Enso code and embeds
/// it in a HTML container.
#[derive(Clone, CloneRef, Debug)]
Expand All @@ -122,10 +110,8 @@ pub struct Model {
/// to EnsoGL shapes, and pass them to the DOM instead.
overlay: overlay::View,
display_object: display::object::Instance,
code_copy_closures: Rc<CloneCell<Vec<CodeCopyClosure>>>,
}


impl Model {
/// Constructor.
fn new(scene: &Scene) -> Self {
Expand Down Expand Up @@ -164,9 +150,7 @@ impl Model {
scene.dom.layers.node_searcher.manage(&inner_dom);
scene.dom.layers.node_searcher.manage(&caption_dom);

let code_copy_closures = default();
Model { outer_dom, inner_dom, caption_dom, overlay, display_object, code_copy_closures }
.init()
Model { outer_dom, inner_dom, caption_dom, overlay, display_object }.init()
}

fn init(self) -> Self {
Expand Down