From 7ee15b118d98af27d861768810144714209d7541 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Thu, 26 Dec 2024 13:47:27 -0500 Subject: [PATCH 1/2] Improve panic messages if retrieving/parsing GL_VERSION fails --- src/web_sys.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/web_sys.rs b/src/web_sys.rs index 20b48fe..a204586 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -253,8 +253,9 @@ impl Context { let (extensions, supported_extensions) = build_extensions!(context, WebGlRenderingContext); // Retrieve and parse `GL_VERSION` - let raw_string = context.get_parameter(VERSION).unwrap().as_string().unwrap(); - let version = Version::parse(&raw_string).unwrap(); + let raw_jsvalue = context.get_parameter(VERSION).expect("context.get_parameter(VERSION) shouldn't throw"); + let raw_string = raw_jsvalue.as_string().unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue)); + let version = Version::parse(&raw_string).expect("context.get_parameter(VERSION) should be parseable as an OpenGL version"); Self { raw: RawRenderingContext::WebGl1(context), @@ -279,8 +280,9 @@ impl Context { let (extensions, supported_extensions) = build_extensions!(context, WebGl2RenderingContext); // Retrieve and parse `GL_VERSION` - let raw_string = context.get_parameter(VERSION).unwrap().as_string().unwrap(); - let version = Version::parse(&raw_string).unwrap(); + let raw_jsvalue = context.get_parameter(VERSION).expect("context.get_parameter(VERSION) shouldn't throw"); + let raw_string = raw_jsvalue.as_string().unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue)); + let version = Version::parse(&raw_string).expect("context.get_parameter(VERSION) should be parseable as an OpenGL version"); Self { raw: RawRenderingContext::WebGl2(context), From 8ad4d82aa24a3081afd095b2f6ea937a6db3acf8 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Wed, 1 Jan 2025 22:40:41 -0500 Subject: [PATCH 2/2] Format --- src/web_sys.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/web_sys.rs b/src/web_sys.rs index a204586..ab2045f 100644 --- a/src/web_sys.rs +++ b/src/web_sys.rs @@ -253,9 +253,14 @@ impl Context { let (extensions, supported_extensions) = build_extensions!(context, WebGlRenderingContext); // Retrieve and parse `GL_VERSION` - let raw_jsvalue = context.get_parameter(VERSION).expect("context.get_parameter(VERSION) shouldn't throw"); - let raw_string = raw_jsvalue.as_string().unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue)); - let version = Version::parse(&raw_string).expect("context.get_parameter(VERSION) should be parseable as an OpenGL version"); + let raw_jsvalue = context + .get_parameter(VERSION) + .expect("context.get_parameter(VERSION) shouldn't throw"); + let raw_string = raw_jsvalue + .as_string() + .unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue)); + let version = Version::parse(&raw_string) + .expect("context.get_parameter(VERSION) should be parseable as an OpenGL version"); Self { raw: RawRenderingContext::WebGl1(context), @@ -280,9 +285,14 @@ impl Context { let (extensions, supported_extensions) = build_extensions!(context, WebGl2RenderingContext); // Retrieve and parse `GL_VERSION` - let raw_jsvalue = context.get_parameter(VERSION).expect("context.get_parameter(VERSION) shouldn't throw"); - let raw_string = raw_jsvalue.as_string().unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue)); - let version = Version::parse(&raw_string).expect("context.get_parameter(VERSION) should be parseable as an OpenGL version"); + let raw_jsvalue = context + .get_parameter(VERSION) + .expect("context.get_parameter(VERSION) shouldn't throw"); + let raw_string = raw_jsvalue + .as_string() + .unwrap_or_else(|| panic!("{:?} should be a string", raw_jsvalue)); + let version = Version::parse(&raw_string) + .expect("context.get_parameter(VERSION) should be parseable as an OpenGL version"); Self { raw: RawRenderingContext::WebGl2(context),