Skip to content

Fix TODOs of unwrap calls by implementing Error Variants#1389

Open
belohnung wants to merge 5 commits intoaya-rs:mainfrom
belohnung:fix-panics
Open

Fix TODOs of unwrap calls by implementing Error Variants#1389
belohnung wants to merge 5 commits intoaya-rs:mainfrom
belohnung:fix-panics

Conversation

@belohnung
Copy link
Copy Markdown
Contributor

@belohnung belohnung commented Nov 10, 2025

This PR addresses several potential panic scenarios by introducing
proper error handling:

New error variants added:

  • RelocationError::UnsupportedRelocationTarget for unsupported
    symbol kinds in relocations
  • ProgramError::InvalidInterfaceName for invalid network interface
    names
  • ProgramError::InvalidName updated to include optional NulError
    source
  • LinkError::InvalidPath for invalid paths

The extra commit which does not produce a diff and had been merged before IIRC.


This change is Reviewable

@netlify
Copy link
Copy Markdown

netlify Bot commented Nov 10, 2025

Deploy Preview for aya-rs-docs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 60b8fba
🔍 Latest deploy log https://app.netlify.com/projects/aya-rs-docs/deploys/69dd7b6b68ce3f0008550847
😎 Deploy Preview https://deploy-preview-1389--aya-rs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@mergify mergify Bot added aya This is about aya (userspace) aya-obj Relating to the aya-obj crate labels Nov 10, 2025
Copy link
Copy Markdown
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tamird reviewed 1 of 1 files at r2, 8 of 8 files at r3, 4 of 4 files at r4, all commit messages.
Reviewable status: all files reviewed, 15 unresolved discussions (waiting on @belohnung)


-- commits line 8 at r3:
can you squash these? i don't see the need for these commits

Code quote:

New commits in r1 on 6/14/2024 at 1:41 PM:
- 212eb53: fix(aya): fix panic when creating map on custom ubuntu kernel

New commits in r2 on 11/10/2025 at 4:07 PM:
- 1dfea36: Merge branch 'aya-rs:main' into main

New commits in r3 on 11/10/2025 at 4:31 PM:
- a471a9a: fix: replace panics with proper error handling

aya/src/programs/mod.rs line 188 at r3 (raw file):

        /// source error
        #[source]
        source: std::ffi::NulError,

add NulError to the imports at the top plz


aya/src/programs/mod.rs line 231 at r3 (raw file):

    Btf(#[from] BtfError),

    /// The program is not attached.

please update


aya/src/programs/mod.rs line 238 at r3 (raw file):

        /// source error
        #[source]
        source: Option<std::ffi::NulError>,

should not be optional


aya/src/programs/mod.rs line 603 at r3 (raw file):

        use std::os::unix::ffi::OsStrExt as _;

        let path_string = CString::new(path.as_ref().as_os_str().as_bytes()).map_err(|e| {

please call this source instead of e


aya/src/programs/mod.rs line 604 at r3 (raw file):

        let path_string = CString::new(path.as_ref().as_os_str().as_bytes()).map_err(|e| {
            ProgramError::InvalidName {

this is misleading, this is an invalid path, not an invalid name.


aya/src/programs/mod.rs line 706 at r3 (raw file):

    let prog_name = if let Some(name) = name.as_deref() {
        let prog_name = CString::new(name).map_err(|err @ std::ffi::NulError { .. }| {

the source error is right here

this code should be

    let prog_name = name.as_deref().map(|name| {
        CString::new(name).map_err(|source| {
            let name = name.to_owned();
            ProgramError::InvalidName { name, source }
        })
    }).transpose()?;

aya/src/maps/info.rs line 121 at r3 (raw file):

        use std::os::unix::ffi::OsStrExt as _;

        let path_string = CString::new(path.as_ref().as_os_str().as_bytes()).map_err(|_| {

can you keep the original error as #[source]?


aya/src/programs/info.rs line 224 at r3 (raw file):

        let path_string = CString::new(path.as_ref().as_os_str().as_bytes()).map_err(|e| {
            ProgramError::InvalidName {

ditto, misleading


aya-obj/src/relocation.rs line 95 at r3 (raw file):

        symbol_kind: SymbolKind,
        /// The relocation size
        size: u8,

why is the size useful?


aya-obj/src/relocation.rs line 404 at r3 (raw file):

                    // R_BPF_64_64 this is a ld_imm64 text relocation
                    SymbolKind::Section if rel.size == 64 => sym.address + ins.imm as u64,
                    _ => {

s/_/symbol_kind/ so it's clear this is not dropped on the floor


aya/src/programs/links.rs line 353 at r3 (raw file):

        let path_string =
            CString::new(path.as_ref().as_os_str().as_bytes()).map_err(|e| LinkError::InvalidPath {

please call this source instead of e


aya/src/programs/links.rs line 607 at r3 (raw file):

        /// source error
        #[source]
        source: std::ffi::NulError,

import please


aya/src/programs/xdp.rs line 107 at r3 (raw file):

    /// transparently falls back to the legacy netlink-based attach path.
    pub fn attach(&mut self, interface: &str, flags: XdpFlags) -> Result<XdpLinkId, ProgramError> {
        let c_interface = CString::new(interface).map_err(|e| ProgramError::InvalidInterfaceName {

please call this source instead of e


aya/src/programs/raw_trace_point.rs line 54 at r3 (raw file):

    /// The returned value can be used to detach, see [RawTracePoint::detach].
    pub fn attach(&mut self, tp_name: &str) -> Result<RawTracePointLinkId, ProgramError> {
        let tp_name_c = CString::new(tp_name).map_err(|e| ProgramError::InvalidName {

please call this source instead of e

@tamird
Copy link
Copy Markdown
Member

tamird commented Nov 11, 2025

CI is failing.

@belohnung
Copy link
Copy Markdown
Contributor Author

yes, can you help me figure out what the problem is?

@tamird
Copy link
Copy Markdown
Member

tamird commented Nov 11, 2025

cargo xtask public-api failed and the error message says: aya-obj public API changed; re-run with --bless

Copy link
Copy Markdown
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tamird reviewed 9 of 9 files at r6, 9 of 9 files at r7, 11 of 11 files at r8, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @belohnung)


aya-obj/src/relocation.rs line 95 at r3 (raw file):

Previously, tamird (Tamir Duberstein) wrote…

why is the size useful?

maybe relocation number would be better, like above


aya/src/maps/mod.rs line 120 at r8 (raw file):

        /// source error
        #[source]
        source: std::ffi::NulError,

add this to the use at the top plz


aya/src/programs/links.rs line 605 at r8 (raw file):

    InvalidPath {
        /// path
        path: String,

make this a PathBuf so you don't have to use .display() which is lossy


aya/src/maps/info.rs line 122 at r6 (raw file):

        let path_string = CString::new(path.as_ref().as_os_str().as_bytes()).map_err(|source| {
            MapError::InvalidName {

should be InvalidPath, no?


aya/src/programs/mod.rs line 245 at r8 (raw file):

    InvalidPath {
        /// path
        path: String,

make this a PathBuf so you don't have to use .display() which is lossy

@belohnung belohnung force-pushed the fix-panics branch 3 times, most recently from 1fb4bb1 to ebc2b62 Compare November 12, 2025 00:24
Copy link
Copy Markdown
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alessandrod could you PTAL?

@tamird reviewed 11 of 11 files at r10, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @belohnung)

Comment thread aya-obj/src/relocation.rs Outdated

/// Unsupported relocation
#[error(
"unsupported relocation target: symbol kind `{symbol_kind:?}` at symbol address #{relocation_number}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be unsupported relocation target {symbol_kind:?} applying relocation #{relocation_number}"` to match the above?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@tamird tamird marked this pull request as draft February 17, 2026 16:18
@belohnung belohnung marked this pull request as ready for review March 1, 2026 01:58
@tamird
Copy link
Copy Markdown
Member

tamird commented Apr 13, 2026

@belohnung could you please rebase and reply to outstanding comments in reviewable

@belohnung belohnung requested a review from a team as a code owner April 13, 2026 20:13
Copy link
Copy Markdown
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reply to comments in reviewable, that helps me track the review. Thanks!

Comment thread aya-obj/src/relocation.rs Outdated

/// Unsupported relocation
#[error(
"unsupported relocation target: symbol kind `{symbol_kind:?}` at symbol address #{relocation_number}"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

This commit addresses several potential panic scenarios by introducing
proper error handling.
@belohnung
Copy link
Copy Markdown
Contributor Author

-- commits line 8 at r3:

Previously, tamird (Tamir Duberstein) wrote…

can you squash these? i don't see the need for these commits

Done.

Copy link
Copy Markdown
Member

@tamird tamird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR needs a rebase, CI seems not to be running.

@tamird reviewed 11 files and all commit messages, made 4 comments, and resolved 2 discussions.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on belohnung).


aya/src/programs/links.rs line 351 at r15 (raw file):

        use std::os::unix::ffi::OsStrExt as _;

        let path_string = CString::new(path.as_ref().as_os_str().as_bytes()).map_err(|source| {

above this line, please write let path = path.as_ref(); to reduce repetition


aya/src/programs/tc.rs line 319 at r15 (raw file):

            TcAttachOptions::Netlink(options) => {
                let name = self.data.name.as_deref().unwrap_or_default();
                let name = CString::new(name).map_err(TcError::from)?;

please update TcError::NulError to also carry the input


aya/src/programs/mod.rs line 616 at r15 (raw file):

        use std::os::unix::ffi::OsStrExt as _;

        let path_string = CString::new(path.as_ref().as_os_str().as_bytes()).map_err(|source| {

same here, above this line please write let path = path.as_ref(); to reduce duplication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aya This is about aya (userspace) aya-obj Relating to the aya-obj crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants