diff --git a/lib/arrow/shuttles/shapes_upload.ex b/lib/arrow/shuttles/shapes_upload.ex index 08c44caad..cc9556aa9 100644 --- a/lib/arrow/shuttles/shapes_upload.ex +++ b/lib/arrow/shuttles/shapes_upload.ex @@ -77,7 +77,7 @@ defmodule Arrow.Shuttles.ShapesUpload do {:error, error} - _ -> + _ when is_list(placemarks) -> # Multiple placemarks, only capture Placemarks with LineString placemarks = Enum.filter(placemarks, fn pm -> pm["LineString"] end) @@ -85,6 +85,14 @@ defmodule Arrow.Shuttles.ShapesUpload do Enum.map(placemarks, fn pm -> %{name: pm["name"], coordinates: process_coordinates(pm["LineString"]["coordinates"])} end)} + + nil -> + {:error, "Failed to parse shape from kml, placemarks are missing."} + + _ -> + {:error, + {"Failed to parse shape from kml, placemarks are of unexpected type.", + [inspect(placemarks)]}} end end diff --git a/test/arrow_web/controllers/shape_controller_test.exs b/test/arrow_web/controllers/shape_controller_test.exs index 98ef2dfbb..a64f3eca7 100644 --- a/test/arrow_web/controllers/shape_controller_test.exs +++ b/test/arrow_web/controllers/shape_controller_test.exs @@ -34,6 +34,13 @@ defmodule ArrowWeb.ShapeControllerTest do filename: "some_file.kml" } } + @missing_placemarks_upload_attrs %{ + name: nil, + filename: %Plug.Upload{ + path: "test/support/fixtures/kml/missing_placemarks.kml", + filename: "missing_placemarks.kml" + } + } @create_attrs [ {0, @@ -142,6 +149,14 @@ defmodule ArrowWeb.ShapeControllerTest do assert html_response(conn, 200) =~ "Components.ShapeViewMap" end + @tag :authenticated_admin + test "renders errors when data is missing", %{conn: conn} do + conn = post(conn, ~p"/shapes_upload", shapes_upload: @missing_placemarks_upload_attrs) + assert html_response(conn, 200) =~ "Failed to parse shape from kml, placemarks are missing." + assert html_response(conn, 200) =~ "new shapes" + assert html_response(conn, 200) =~ "Components.ShapeViewMap" + end + @tag :authenticated_admin test "renders errors when file read fails", %{conn: conn} do conn = post(conn, ~p"/shapes_upload", shapes_upload: @file_read_fail_attrs) diff --git a/test/support/fixtures/kml/missing_placemarks.kml b/test/support/fixtures/kml/missing_placemarks.kml new file mode 100644 index 000000000..c3f9bebc2 --- /dev/null +++ b/test/support/fixtures/kml/missing_placemarks.kml @@ -0,0 +1,10 @@ + + + + MBTA Shuttles - 20260724 + GL-C: Cleveland Circle - Kenmore - toward Cleveland Circle + + -71.09574,42.34879 -71.09574,42.34879 -71.09574,42.34879 -71.09513,42.3488 -71.09509,42.34881 -71.09497,42.34881 -71.09499,42.34904 -71.09499,42.34907 -71.09499,42.34914 -71.0951,42.34913 -71.09514,42.34913 -71.09525,42.34913 -71.09546,42.34913 -71.09561,42.34912 -71.09569,42.34912 -71.09575,42.34912 -71.09576,42.34912 -71.09578,42.34912 -71.09581,42.34912 -71.09585,42.34911 -71.09591,42.3491 -71.09596,42.34909 -71.09604,42.34908 -71.09616,42.34905 -71.09623,42.34904 -71.09633,42.34903 -71.09637,42.34902 -71.09642,42.34901 -71.09649,42.34901 -71.09656,42.349 -71.0966,42.349 -71.09665,42.34899 -71.09669,42.34899 -71.09674,42.34899 -71.09695,42.34893 -71.09741,42.34882 -71.09767,42.34875 -71.09796,42.34867 -71.09817,42.34856 -71.09848,42.34847 -71.09848,42.34847 -71.09957,42.34817 -71.09986,42.34815 -71.10163,42.34766 -71.10172,42.34761 -71.10175,42.34759 -71.10185,42.34754 -71.10201,42.34749 -71.10204,42.34748 -71.10256,42.34734 -71.10261,42.34733 -71.10303,42.34721 -71.10333,42.34713 -71.10345,42.3471 -71.10396,42.34696 -71.10396,42.34696 -71.1041,42.34692 -71.10437,42.34685 -71.10452,42.34683 -71.10467,42.34682 -71.10488,42.34676 -71.10493,42.34675 -71.10495,42.34674 -71.10513,42.34669 -71.10531,42.34664 -71.10553,42.34658 -71.1068,42.34624 -71.10718,42.34614 -71.10746,42.34607 -71.10749,42.34606 -71.10782,42.34598 -71.10901,42.34566 -71.10905,42.34565 -71.10917,42.34561 -71.10929,42.34558 -71.10937,42.34556 -71.11042,42.34527 -71.11078,42.34517 -71.11083,42.34515 -71.111,42.34511 -71.11223,42.34477 -71.11254,42.34468 -71.11254,42.34468 -71.11349,42.34442 -71.11371,42.34436 -71.11423,42.34422 -71.11427,42.34421 -71.11439,42.34418 -71.11452,42.34414 -71.11652,42.34359 -71.11675,42.34353 -71.11691,42.34348 -71.11695,42.34347 -71.11696,42.34347 -71.11709,42.34344 -71.11716,42.34342 -71.11732,42.34337 -71.11807,42.34317 -71.11905,42.34289 -71.11919,42.34285 -71.11975,42.34269 -71.12022,42.34256 -71.12031,42.34254 -71.12088,42.34237 -71.12116,42.3423 -71.1212,42.34229 -71.12129,42.34226 -71.12142,42.34223 -71.12159,42.34218 -71.12205,42.34203 -71.12233,42.34195 -71.12237,42.34194 -71.12237,42.34194 -71.12255,42.3419 -71.12281,42.34183 -71.12298,42.34179 -71.12308,42.34177 -71.12389,42.34159 -71.12413,42.34154 -71.12418,42.34153 -71.12436,42.34149 -71.12462,42.34143 -71.12562,42.34117 -71.12575,42.34114 -71.1259,42.34111 -71.12598,42.34109 -71.12602,42.34107 -71.12617,42.34103 -71.12631,42.34099 -71.12633,42.34098 -71.12649,42.34093 -71.12664,42.34088 -71.12668,42.34086 -71.1268,42.34082 -71.12695,42.34076 -71.1271,42.34071 -71.12725,42.34067 -71.12734,42.34063 -71.12772,42.34051 -71.12817,42.34037 -71.12836,42.34032 -71.12856,42.34026 -71.12872,42.34022 -71.12875,42.34021 -71.12899,42.34015 -71.12923,42.3401 -71.1295,42.34004 -71.12974,42.33999 -71.13,42.33995 -71.13023,42.33991 -71.13046,42.33989 -71.13067,42.33986 -71.13094,42.33984 -71.13109,42.33982 -71.13122,42.33981 -71.13137,42.3398 -71.13151,42.3398 -71.13166,42.33979 -71.13181,42.33979 -71.13196,42.33978 -71.13281,42.33978 -71.13281,42.33978 -71.13299,42.33978 -71.13312,42.33978 -71.13327,42.33978 -71.13341,42.33979 -71.13359,42.33979 -71.13365,42.33979 -71.13376,42.33979 -71.13382,42.33979 -71.13388,42.33979 -71.134,42.33979 -71.1341,42.33978 -71.13421,42.33978 -71.13434,42.33976 -71.13448,42.33973 -71.13475,42.33967 -71.13489,42.33964 -71.13498,42.33962 -71.13504,42.33961 -71.13517,42.33958 -71.13532,42.33953 -71.13535,42.33953 -71.13539,42.33951 -71.13546,42.33949 -71.13554,42.33947 -71.13559,42.33945 -71.1356,42.33945 -71.13574,42.3394 -71.13596,42.33934 -71.13624,42.33926 -71.13651,42.33919 -71.13679,42.33911 -71.13683,42.3391 -71.13688,42.33909 -71.13714,42.33903 -71.13724,42.339 -71.1374,42.33896 -71.13894,42.33859 -71.13898,42.33858 -71.1391,42.33855 -71.1393,42.3385 -71.14026,42.33827 -71.14053,42.33821 -71.14082,42.33815 -71.14111,42.33808 -71.14133,42.33804 -71.14139,42.33802 -71.14165,42.33797 -71.14187,42.33792 -71.14191,42.33791 -71.14203,42.33789 -71.14216,42.33786 -71.14249,42.33779 -71.14249,42.33779 -71.14307,42.33768 -71.14413,42.33746 -71.14472,42.33734 -71.14492,42.3373 -71.14496,42.33729 -71.14509,42.33727 -71.14525,42.33723 -71.14628,42.33701 -71.14635,42.337 -71.1468,42.3369 -71.147,42.33686 -71.14714,42.33683 -71.14727,42.3368 -71.14816,42.3366 -71.14836,42.33655 -71.14865,42.33648 -71.14934,42.3363 -71.14938,42.33629 -71.1496,42.33624 -71.1496,42.33624 -71.14975,42.3362 -71.14992,42.33616 -71.15007,42.33612 -71.15014,42.3361 -71.15021,42.33609 -71.15029,42.33608 -71.15036,42.33607 -71.15056,42.33606 -71.15057,42.33606 -71.15063,42.33606 -71.15069,42.33605 -71.15083,42.33604 -71.15096,42.33604 -71.15101,42.33603 -71.15089,42.33591 -71.15083,42.33591 -71.15068,42.33589 -71.15053,42.33588 -71.1504,42.33587 -71.15036,42.33586 -71.15034,42.33586 -71.15028,42.33586 -71.15021,42.33586 -71.15015,42.33587 -71.15007,42.33589 -71.14993,42.33592 -71.1498,42.33595 -71.14962,42.33599 -71.14956,42.33601 -71.14934,42.33606 -71.1493,42.33607 -71.14905,42.33613 + + +