Skip to content

Commit 3365621

Browse files
committed
og_image: Add debug logging to from_environment() fn
1 parent 4c45d55 commit 3365621

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/crates_io_og_image/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ serde_json = "=1.0.140"
1818
tempfile = "=3.20.0"
1919
thiserror = "=2.0.12"
2020
tokio = { version = "=1.45.1", features = ["process", "fs"] }
21+
tracing = "=0.1.41"
2122

2223
[dev-dependencies]
2324
insta = "=1.43.1"
2425
tokio = { version = "=1.45.1", features = ["macros", "rt-multi-thread"] }
26+
tracing-subscriber = { version = "=0.3.19", features = ["env-filter"] }

crates/crates_io_og_image/src/lib.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub use error::OgImageError;
77

88
use crate::formatting::{serialize_bytes, serialize_number, serialize_optional_number};
99
use bytes::Bytes;
10-
use crates_io_env_vars::var;
10+
use crates_io_env_vars::var_parsed;
1111
use serde::Serialize;
1212
use std::collections::HashMap;
1313
use std::path::PathBuf;
@@ -109,19 +109,26 @@ impl OgImageGenerator {
109109
/// # Ok::<(), crates_io_og_image::OgImageError>(())
110110
/// ```
111111
pub fn from_environment() -> Result<Self, OgImageError> {
112-
let typst_path = var("TYPST_PATH").map_err(OgImageError::EnvVarError)?;
113-
let font_path = var("TYPST_FONT_PATH").map_err(OgImageError::EnvVarError)?;
114-
115-
let mut generator = if let Some(path) = typst_path {
116-
Self::new(PathBuf::from(path))
112+
let typst_path = var_parsed::<PathBuf>("TYPST_PATH");
113+
let typst_path = typst_path.map_err(OgImageError::EnvVarError)?;
114+
let font_path = var_parsed::<PathBuf>("TYPST_FONT_PATH");
115+
let font_path = font_path.map_err(OgImageError::EnvVarError)?;
116+
117+
let mut generator = if let Some(typst_path) = typst_path {
118+
println!("Using TYPST_PATH: {}", typst_path.display());
119+
Self::new(typst_path)
117120
} else {
121+
println!("TYPST_PATH not set, using default 'typst' binary in PATH");
118122
Self::default()
119123
};
120124

121125
if let Some(font_path) = font_path {
122126
let current_dir = std::env::current_dir()?;
123127
let font_path = current_dir.join(font_path).canonicalize()?;
128+
println!("Using TYPST_FONT_PATH: {}", font_path.display());
124129
generator = generator.with_font_path(font_path);
130+
} else {
131+
println!("TYPST_FONT_PATH not set, using default font discovery");
125132
}
126133

127134
Ok(generator)
@@ -325,6 +332,8 @@ impl Default for OgImageGenerator {
325332
#[cfg(test)]
326333
mod tests {
327334
use super::*;
335+
use tracing::subscriber;
336+
use tracing_subscriber::fmt;
328337

329338
const fn author(name: &str) -> OgImageAuthorData<'_> {
330339
OgImageAuthorData::new(name, None)
@@ -450,6 +459,8 @@ mod tests {
450459

451460
#[tokio::test]
452461
async fn test_generate_og_image_snapshot() {
462+
let _guard = subscriber::set_default(fmt().compact().with_test_writer().finish());
463+
453464
let data = create_simple_test_data();
454465

455466
if let Some(image_data) = generate_image(data).await {
@@ -459,6 +470,8 @@ mod tests {
459470

460471
#[tokio::test]
461472
async fn test_generate_og_image_overflow_snapshot() {
473+
let _guard = subscriber::set_default(fmt().compact().with_test_writer().finish());
474+
462475
let data = create_overflow_test_data();
463476

464477
if let Some(image_data) = generate_image(data).await {
@@ -468,6 +481,8 @@ mod tests {
468481

469482
#[tokio::test]
470483
async fn test_generate_og_image_minimal_snapshot() {
484+
let _guard = subscriber::set_default(fmt().compact().with_test_writer().finish());
485+
471486
let data = create_minimal_test_data();
472487

473488
if let Some(image_data) = generate_image(data).await {
@@ -477,6 +492,8 @@ mod tests {
477492

478493
#[tokio::test]
479494
async fn test_generate_og_image_escaping_snapshot() {
495+
let _guard = subscriber::set_default(fmt().compact().with_test_writer().finish());
496+
480497
let data = create_escaping_test_data();
481498

482499
if let Some(image_data) = generate_image(data).await {

0 commit comments

Comments
 (0)