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

Panic in gallery convertor #64

Closed
leewillis77 opened this issue Oct 10, 2024 · 3 comments
Closed

Panic in gallery convertor #64

leewillis77 opened this issue Oct 10, 2024 · 3 comments

Comments

@leewillis77
Copy link

11:12:54AM DBG wordpress_gallery_converter.go:29 > Replacing gallery with figures
panic: runtime error: index out of range [1] with length 0

goroutine 1 [running]:
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator/hugopage.galleryReplacementFunction({0x105461948, 0x14001c63680}, {0x14001b41940, 0xa?, 0x2?})
wp2hugo/internal/hugogenerator/hugopage/wordpress_gallery_converter.go:51 +0x754
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator/hugopage.replaceGalleryWithFigure.func1({0x14001b41940?, 0x1400161d680?, 0x430?})
wp2hugo/internal/hugogenerator/hugopage/wordpress_gallery_converter.go:33 +0x3c
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator/hugopage.replaceAllStringSubmatchFunc(0x14000ac5360, {0x1400058db00, 0x430}, 0x140000266e0)
wp2hugo/internal/hugogenerator/hugopage/wordpress_category_list_converter.go:39 +0x124
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator/hugopage.replaceGalleryWithFigure({0x105461948, 0x14001c63680}, {0x1400058db00, 0x430})
wp2hugo/internal/hugogenerator/hugopage/wordpress_gallery_converter.go:31 +0x90
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator/hugopage.(*Page).getMarkdown(0x140017e82c0, {0x105461948, 0x14001c63680}, {0x1400058db00, 0x430}, {0x0, 0x0, 0x1400230e1db?})
wp2hugo/internal/hugogenerator/hugopage/hugo_page.go:222 +0x80
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator/hugopage.NewPage({0x105461948, 0x14001c63680}, {{0x1400230e1c0, 0x5}, {0x0, 0x0}, 0x0, {0x1400230e1c8, 0x13}, {0x1400230e1db, ...}, ...}, ...)
wp2hugo/internal/hugogenerator/hugopage/hugo_page.go:83 +0x130
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator.Generator.newHugoPage({{0x10500d0d3, 0x6}, {0x105461948, 0x14001c63680}, {0x104ff7ee7, 0x4}, {{0x14000225430, 0xa}, {0x140003afec0, 0x1b}, ...}, ...}, ...)
wp2hugo/internal/hugogenerator/hugo_gen_setup.go:393 +0x15c
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator.Generator.writePage({{0x10500d0d3, 0x6}, {0x105461948, 0x14001c63680}, {0x104ff7ee7, 0x4}, {{0x14000225430, 0xa}, {0x140003afec0, 0x1b}, ...}, ...}, ...)
wp2hugo/internal/hugogenerator/hugo_gen_setup.go:374 +0x178
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator.Generator.writePosts({{0x10500d0d3, 0x6}, {0x105461948, 0x14001c63680}, {0x104ff7ee7, 0x4}, {{0x14000225430, 0xa}, {0x140003afec0, 0x1b}, ...}, ...}, ...)
wp2hugo/internal/hugogenerator/hugo_gen_setup.go:327 +0x1f4
github.com/ashishb/wp2hugo/src/wp2hugo/internal/hugogenerator.Generator.Generate({{0x10500d0d3, 0x6}, {0x105461948, 0x14001c63680}, {0x104ff7ee7, 0x4}, {{0x14000225430, 0xa}, {0x140003afec0, 0x1b}, ...}, ...})
wp2hugo/internal/hugogenerator/hugo_gen_setup.go:95 +0x130
main.generate({{0x14000225430, 0xa}, {0x140003afec0, 0x1b}, {0x0, 0x0}, 0x140004a4ed0, {0x14000225718, 0x5}, {0x140025a0cf0, ...}, ...}, ...)
wp2hugo/cmd/wp2hugo/main.go:71 +0x278
main.handle({0x16b1933de, 0x27})
wp2hugo/cmd/wp2hugo/main.go:55 +0xe8
main.main()
wp2hugo/cmd/wp2hugo/main.go:41 +0xd4

@leewillis77
Copy link
Author

I suspect this is caused by the importer assuming that a gallery shortcode will have a list of IDs, however, that's not always the case. My export contains gallery shortcodes in the following format (the link="file" bit I don't think is relevant, but I've included it for completeness).

[gallery link="file"]

That will include all media that is attached to the post by default on WordPress.

ashishb added a commit that referenced this issue Oct 12, 2024
If the WordPress `gallery` shortcode is missing `ids` then persist the
original shortcode in the generated Markdown code.

Ref: #64
From the original comment

```
I suspect this is caused by the importer assuming that a gallery shortcode will have a list of IDs, however, that's not always the case. My export contains gallery shortcodes in the following format (the link="file" bit I don't think is relevant, but I've included it for completeness).

[gallery link="file"]

That will include all media that is attached to the post by default on WordPress.
```
@ashishb
Copy link
Owner

ashishb commented Oct 12, 2024

Thanks for reporting this.
I am not sure what the proper fix is here as I don't have a sample to test with.

But I have added to code to gracefully log an error and persist the original shortcode in the output Markdown

e33ea8a

@leewillis77
Copy link
Author

Thanks for this. I've raised a follow-on issue with sample XML and the corresponding WordPress page that generated it in case you want to handle that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants