Skip to content

Commit 76c5023

Browse files
committed
og_image: Add debug logging to from_environment() fn
1 parent 7c73cdf commit 76c5023

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-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: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ mod formatting;
66
pub use error::OgImageError;
77

88
use crate::formatting::{serialize_bytes, serialize_number, serialize_optional_number};
9+
use anyhow::Context;
910
use bytes::Bytes;
10-
use crates_io_env_vars::var;
11+
use crates_io_env_vars::var_parsed;
1112
use serde::Serialize;
1213
use std::collections::HashMap;
1314
use std::path::PathBuf;
@@ -109,19 +110,28 @@ impl OgImageGenerator {
109110
/// # Ok::<(), crates_io_og_image::OgImageError>(())
110111
/// ```
111112
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))
113+
let typst_path = var_parsed::<PathBuf>("TYPST_PATH");
114+
let typst_path = typst_path.map_err(OgImageError::EnvVarError)?;
115+
let font_path = var_parsed::<PathBuf>("TYPST_FONT_PATH");
116+
let font_path = font_path.map_err(OgImageError::EnvVarError)?;
117+
118+
let mut generator = if let Some(typst_path) = typst_path {
119+
println!("Using TYPST_PATH: {}", typst_path.display());
120+
Self::new(typst_path)
117121
} else {
122+
println!("TYPST_PATH not set, using default 'typst' binary in PATH");
118123
Self::default()
119124
};
120125

121126
if let Some(font_path) = font_path {
127+
println!("Using TYPST_FONT_PATH: {}", font_path.display());
122128
let current_dir = std::env::current_dir()?;
129+
dbg!(&current_dir);
123130
let font_path = current_dir.join(font_path).canonicalize()?;
131+
dbg!(&font_path);
124132
generator = generator.with_font_path(font_path);
133+
} else {
134+
println!("TYPST_FONT_PATH not set, using default font discovery");
125135
}
126136

127137
Ok(generator)
@@ -325,6 +335,8 @@ impl Default for OgImageGenerator {
325335
#[cfg(test)]
326336
mod tests {
327337
use super::*;
338+
use tracing::subscriber;
339+
use tracing_subscriber::fmt;
328340

329341
const fn author(name: &str) -> OgImageAuthorData<'_> {
330342
OgImageAuthorData::new(name, None)
@@ -451,6 +463,8 @@ mod tests {
451463

452464
#[tokio::test]
453465
async fn test_generate_og_image_snapshot() {
466+
let _guard = subscriber::set_default(fmt().compact().with_test_writer().finish());
467+
454468
let data = create_simple_test_data();
455469

456470
if let Some(image_data) = generate_image(data).await {
@@ -460,6 +474,8 @@ mod tests {
460474

461475
#[tokio::test]
462476
async fn test_generate_og_image_overflow_snapshot() {
477+
let _guard = subscriber::set_default(fmt().compact().with_test_writer().finish());
478+
463479
let data = create_overflow_test_data();
464480

465481
if let Some(image_data) = generate_image(data).await {
@@ -469,6 +485,8 @@ mod tests {
469485

470486
#[tokio::test]
471487
async fn test_generate_og_image_minimal_snapshot() {
488+
let _guard = subscriber::set_default(fmt().compact().with_test_writer().finish());
489+
472490
let data = create_minimal_test_data();
473491

474492
if let Some(image_data) = generate_image(data).await {
@@ -478,6 +496,8 @@ mod tests {
478496

479497
#[tokio::test]
480498
async fn test_generate_og_image_escaping_snapshot() {
499+
let _guard = subscriber::set_default(fmt().compact().with_test_writer().finish());
500+
481501
let data = create_escaping_test_data();
482502

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

0 commit comments

Comments
 (0)